1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
<%@ jet package="org.eclipse.emf.test.common.templates" imports="java.util.* org.eclipse.emf.common.util.*" class="DiagnosticTestGen"%>
<%
/**
* Copyright (c) 2006-2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* IBM - Initial API and implementation
*/
%>
<%
String name = (String)((Object[])argument)[0];
Diagnostic rootDiagnostic = (Diagnostic)((Object[])argument)[1];
TreeIterator<Diagnostic> diagnosticIterator = new AbstractTreeIterator<Diagnostic>(rootDiagnostic)
{
private static final long serialVersionUID = 1L;
@Override
protected Iterator<? extends Diagnostic> getChildren(Object object)
{
return ((Diagnostic)object).getChildren().iterator();
}
};
class Helper
{
public String toString(Throwable throwable)
{
StringBuilder sb = new StringBuilder();
sb.append(throwable.getClass().getName());
sb.append("#").append(throwable.getMessage());
Throwable cause = throwable.getCause();
if (cause != null && cause != throwable)
{
sb.append("--").append(toString(cause));
}
return sb.toString();
}
protected String removeObjectHashCode(String string)
{
return string.replaceAll("@\\w+", "");
}
public String toCodeString(String string)
{
return "\"" + string.replaceAll("\\\\", "\\\\\\\\").replaceAll("\\\"", "\\\\\"") + "\"";
}
public String getDiagnosticSeverity(int value)
{
switch(value)
{
case Diagnostic.CANCEL:
return "Diagnostic.CANCEL";
case Diagnostic.OK:
return "Diagnostic.OK";
case Diagnostic.INFO:
return "Diagnostic.INFO";
case Diagnostic.ERROR:
return "Diagnostic.ERROR";
case Diagnostic.WARNING:
return "Diagnostic.WARNING";
default:
return Integer.toString(value);
}
}
}
Helper helper = new Helper();
%>
import java.util.Iterator;
import org.eclipse.emf.common.util.AbstractTreeIterator;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import org.eclipse.emf.test.common.TestUtil;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class <%=name%>DiagnosticTest
{
protected Diagnostic diagnostic;
@Before
public void setUp() throws Exception
{
//TODO:Instantiates the diagnostic here
assertNotNull(diagnostic);
}
@Test
public void testDiagnostic() throws Exception
{
TreeIterator<Diagnostic> diagnosticIterator = new AbstractTreeIterator<Diagnostic>(diagnostic)
{
private static final long serialVersionUID = 1L;
@Override
protected Iterator<? extends Diagnostic> getChildren(Object object)
{
return ((Diagnostic)object).getChildren().iterator();
}
};
<%int count=0; while(diagnosticIterator.hasNext()){Diagnostic diagnostic = diagnosticIterator.next(); count++;%>
Diagnostic diagnostic<%=count%> = diagnosticIterator.next();
assertEquals(<%=helper.getDiagnosticSeverity(diagnostic.getSeverity())%>, diagnostic<%=count%>.getSeverity());
assertEquals(<%=helper.toCodeString(diagnostic.getSource())%>, diagnostic<%=count%>.getSource());
assertEquals(<%=helper.removeObjectHashCode(helper.toCodeString(diagnostic.getMessage()))%>, removeObjectHashCode(diagnostic<%=count%>.getMessage()));
assertEquals(<%=diagnostic.getCode()%>, diagnostic<%=count%>.getCode());
assertEquals(<%=diagnostic.getChildren().size()%>, diagnostic<%=count%>.getChildren().size());
assertEquals(<%=diagnostic.getData().size()%>, diagnostic<%=count%>.getData().size());
<%Throwable throwable = diagnostic.getException(); if (throwable != null) {%>assertEquals(<%=helper.toCodeString(helper.toString(diagnostic.getException()))%>, toString(diagnostic<%=count%>.getException()));
<%} else {%>assertNull(diagnostic<%=count%>.getException());<%} if (diagnosticIterator.hasNext()) {stringBuffer.append(NL);}}%>
assertFalse(diagnosticIterator.hasNext());
}
protected String toString(Throwable throwable)
{
StringBuilder sb = new StringBuilder();
sb.append(throwable.getClass().getName());
sb.append("#").append(throwable.getMessage());
Throwable cause = throwable.getCause();
if (cause != null && cause != throwable)
{
sb.append("--").append(toString(cause));
}
return sb.toString();
}
protected String removeObjectHashCode(String string)
{
return string.replaceAll("@\\w+", "");
}
}
|