Commit 2fec5c4c authored by Marco Konersmann's avatar Marco Konersmann

Splits the JACK3 case study JUnit test into separate verification methods

parent 6e4846a2
......@@ -8,6 +8,7 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
import org.codeling.lang.jee7.JEE7LanguageDefinition;
import org.codeling.lang.jee7.JEE7UMLLanguageDefinition;
......@@ -17,20 +18,27 @@ import org.codeling.utils.Models;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.uml2.uml.Comment;
import org.eclipse.uml2.uml.Component;
import org.eclipse.uml2.uml.Interface;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Operation;
import org.eclipse.uml2.uml.PackageableElement;
import org.eclipse.uml2.uml.Realization;
import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.UMLPackage;
import org.junit.BeforeClass;
import org.junit.Test;
import de.mkonersmann.advert.java.embed.ASTUtils;
import de.mkonersmann.advert.java.embed.JDTUtils;
public class JACK3_UML_CaseStudy {
......@@ -39,7 +47,6 @@ public class JACK3_UML_CaseStudy {
private static IJavaProject webProject;
private static LinkedList<IJavaProject> projects = new LinkedList<>();
@BeforeClass
public static void importProjects() throws CoreException {
CaseStudyCommons c = new CaseStudyCommons();
IProject productProject = c.copyImportProject(c.getJACKPath());
......@@ -53,8 +60,10 @@ public class JACK3_UML_CaseStudy {
projects.addAll(Arrays.asList(coreProject, businessProject, webProject));
}
@Test
public void addNewComponentWithinCore() throws CoreException, CodelingException, IOException {
@BeforeClass
public static void addNewComponentWithinCore() throws CoreException, CodelingException, IOException {
importProjects();
// Translate code to UML model
JEE7LanguageDefinition implementationLanguage = new JEE7LanguageDefinition();
JEE7UMLLanguageDefinition specificationLanguage = new JEE7UMLLanguageDefinition();
......@@ -109,12 +118,25 @@ public class JACK3_UML_CaseStudy {
&& myAccountViewRealization != null)
break;
}
assertNotNull(loginViewComponent);
assertNotNull(loginViewInterface);
assertNotNull(loginViewRealization);
assertNotNull(myAccountViewComponent);
assertNotNull(myAccountViewInterface);
assertNotNull(myAccountViewRealization);
Operation op = null;
for (PackageableElement e : jack3core.getPackagedElements()) {
if (e instanceof Interface && "CourseService".equals(e.getName())) {
for (Operation o : ((Interface) e).getOperations()) {
if ("getAllCoursesForUser".equals(o.getName())) {
op = o;
break;
}
}
}
}
// assertNotNull(loginViewComponent);
// assertNotNull(loginViewInterface);
// assertNotNull(loginViewRealization);
// assertNotNull(myAccountViewComponent);
// assertNotNull(myAccountViewInterface);
// assertNotNull(myAccountViewRealization);
// assertNotNull(op);
// Update UML model
// New AdministrationService
......@@ -127,14 +149,25 @@ public class JACK3_UML_CaseStudy {
r.getClients().add(component);
// Delete LoginView
loginViewRealization.destroy();
loginViewInterface.destroy();
loginViewComponent.destroy();
if (loginViewComponent != null && loginViewInterface != null && loginViewRealization != null) {
loginViewRealization.destroy();
loginViewInterface.destroy();
loginViewComponent.destroy();
}
// Rename MyAccountView
myAccountViewComponent.setName("AccountDetailsView");
myAccountViewInterface.setName("AccountDetailsView");
myAccountViewRealization.setName("AccountDetailsView");
if (myAccountViewComponent != null && myAccountViewInterface != null && myAccountViewRealization != null) {
myAccountViewComponent.setName("AccountDetailsView");
myAccountViewInterface.setName("AccountDetailsView");
myAccountViewRealization.setName("AccountDetailsView");
}
// Add Time Resoruce Demand
if (op != null) {
Comment comment = UMLFactory.eINSTANCE.createComment();
comment.setBody("Time Resource Demand: [50ms]");
op.getOwnedComments().add(comment);
}
Models.store(modelElements, "/architecture-carrying-code-temp/specification-model-changed.xmi");
......@@ -144,7 +177,10 @@ public class JACK3_UML_CaseStudy {
specificationLanguage, null, projects);
long endToCode = System.nanoTime();
System.out.println("Required time for translation to code: " + (endToCode - startToCode) + " nano seconds.");
}
@Test
public void verifyNewElement() throws JavaModelException {
// Verify changed code
String packageName = "new_architecture_elements";
String compilationUnitName = "AdministrationService.java";
......@@ -154,16 +190,32 @@ public class JACK3_UML_CaseStudy {
compilationUnitExists(webProject, packageName, compilationUnitName));
assertTrue("Addition did not create new compilation unit",
compilationUnitExists(coreProject, packageName, compilationUnitName));
}
@Test
public void verifyDeletedElement() throws JavaModelException {
assertFalse("Deletion did not work",
compilationUnitExists(webProject, "de.uni_due.s3.jack3.beans", "LoginView.java"));
}
@Test
public void verifyRenamedElement() throws JavaModelException {
assertTrue("Change (renaming) did not work",
compilationUnitExists(webProject, "de.uni_due.s3.jack3.beans", "AccountDetailsView.java"));
assertFalse("Change (renaming) did not change the old file, but only created a new one",
compilationUnitExists(webProject, "de.uni_due.s3.jack3.beans", "MyAccountView.java"));
}
@Test
public void verifyAddedIALElement() throws NoSuchElementException, JavaModelException {
IMethod method = getMethod(coreProject, "de.uni_due.s3.jack3.services", "CourseService.java",
"getAllCoursesForUser", new String[] { "QUser;" });
IAnnotation annotation = method.getAnnotation("TimeResourceDemand");
assertTrue("Did not add time resource demand to the code.", annotation.exists());
assertTrue("The time resource demand duration was not added to the code.",
annotation.getSource().contains("50ms"));
}
private boolean compilationUnitExists(IJavaProject project, String packageName, String compilationUnitName)
throws JavaModelException {
IPackageFragment packageFragment = ASTUtils.getPackageFragment(packageName, Arrays.asList(project));
......@@ -172,4 +224,12 @@ public class JACK3_UML_CaseStudy {
return packageFragment.getCompilationUnit(compilationUnitName).exists();
}
private IMethod getMethod(IJavaProject project, String packageName, String compilationUnitName, String methodName,
String[] argumentTypes) throws NoSuchElementException, JavaModelException {
IPackageFragment packageFragment = ASTUtils.getPackageFragment(packageName, Arrays.asList(project));
ICompilationUnit cu = packageFragment.getCompilationUnit(compilationUnitName);
return cu.getType(compilationUnitName.substring(0, compilationUnitName.length() - ".java".length()))
.getMethod(methodName, argumentTypes);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment