List of usage examples for org.objectweb.asm.tree ClassNode ClassNode
public ClassNode()
From source file:org.wisdom.ipojo.module.WisdomControllerVisitorTest.java
License:Apache License
@Test public void testOnlyController() { Reporter reporter = mock(Reporter.class); ComponentWorkbench workbench = mock(ComponentWorkbench.class); when(workbench.getType()).thenReturn(Type.getType(MyComponent.class)); when(workbench.getClassNode()).thenReturn(new ClassNode()); doAnswer(new Answer<Void>() { @Override/*from w ww .j a v a 2 s.com*/ public Void answer(InvocationOnMock invocation) throws Throwable { root = (Element) invocation.getArguments()[0]; return null; } }).when(workbench).setRoot(any(Element.class)); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { instance = (Element) invocation.getArguments()[0]; return null; } }).when(workbench).setInstance(any(Element.class)); WisdomControllerVisitor visitor = new WisdomControllerVisitor(workbench, reporter); visitor.visitEnd(); // Check the generated Component assertThat(root).isNotNull(); assertThat(root.getName()).isEqualTo("component"); assertThat(root.getAttribute("classname")).isEqualTo(MyComponent.class.getName()); // Check the Provides element assertThat(root.getElements("provides")).hasSize(1); // Check the Instance declaration assertThat(instance).isNotNull(); assertThat(instance.getAttribute("component")).isEqualTo(MyComponent.class.getName()); }
From source file:org.wisdom.ipojo.module.WisdomControllerVisitorTest.java
License:Apache License
@Test public void testWhenAnotherRootIsAlreadyDeclared() { Reporter reporter = mock(Reporter.class); ComponentWorkbench workbench = mock(ComponentWorkbench.class); // Set another root when(workbench.getRoot()).thenReturn(new Element("another", "root")); when(workbench.getType()).thenReturn(Type.getType(MyComponent.class)); when(workbench.getClassNode()).thenReturn(new ClassNode()); doAnswer(new Answer<Void>() { @Override/* w ww . ja va 2 s . c o m*/ public Void answer(InvocationOnMock invocation) throws Throwable { root = (Element) invocation.getArguments()[0]; return null; } }).when(workbench).setRoot(any(Element.class)); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { instance = (Element) invocation.getArguments()[0]; return null; } }).when(workbench).setInstance(any(Element.class)); WisdomControllerVisitor visitor = new WisdomControllerVisitor(workbench, reporter); visitor.visitEnd(); // Check that nothing is generated assertThat(root).isNull(); assertThat(instance).isNull(); }
From source file:org.wisdom.ipojo.module.WisdomModelVisitorTest.java
License:Apache License
@Test public void parseRegularModel() { Reporter reporter = new SystemReporter(); ComponentWorkbench workbench = mock(ComponentWorkbench.class); when(workbench.getType()).thenReturn(Type.getType(MyComponent.class)); when(workbench.getClassNode()).thenReturn(new ClassNode()); when(workbench.getElements()).thenReturn(elements); FieldNode node = new FieldNode(Opcodes.ACC_PROTECTED, "model", Type.getDescriptor(Crud.class), null, null); WisdomModelVisitor visitor = new WisdomModelVisitor(workbench, reporter, node); visitor.visit("value", "entity"); visitor.visitEnd();// ww w. j a va 2 s . c o m assertThat(elements).hasSize(1); Element element = elements.keySet().iterator().next(); assertThat(element.getName()).isEqualTo("requires"); assertThat(element.getAttribute("field")).isEqualTo("model"); assertThat(element.getAttribute("filter")).contains("=entity)"); }
From source file:org.wisdom.ipojo.module.WisdomModelVisitorTest.java
License:Apache License
@Test public void parseEmptyAnnotation() { Reporter reporter = new SystemReporter(); ComponentWorkbench workbench = mock(ComponentWorkbench.class); when(workbench.getType()).thenReturn(Type.getType(MyComponent.class)); when(workbench.getClassNode()).thenReturn(new ClassNode()); when(workbench.getElements()).thenReturn(elements); FieldNode node = new FieldNode(Opcodes.ACC_PROTECTED, "model", Type.getDescriptor(Crud.class), null, null); WisdomModelVisitor visitor = new WisdomModelVisitor(workbench, reporter, node); visitor.visitEnd();/* w w w .j a va 2s . c o m*/ assertThat(elements).hasSize(0); }
From source file:org.wisdom.ipojo.module.WisdomModelVisitorTest.java
License:Apache License
@Test public void parseModelOnNotCrudField() { Reporter reporter = new SystemReporter(); ComponentWorkbench workbench = mock(ComponentWorkbench.class); when(workbench.getType()).thenReturn(Type.getType(MyComponent.class)); when(workbench.getClassNode()).thenReturn(new ClassNode()); when(workbench.getElements()).thenReturn(elements); FieldNode node = new FieldNode(Opcodes.ACC_PROTECTED, "model", Type.getDescriptor(String.class), null, null);//from w ww .j av a2s .c o m WisdomModelVisitor visitor = new WisdomModelVisitor(workbench, reporter, node); visitor.visit("value", "entity"); visitor.visitEnd(); assertThat(elements).hasSize(1); Element element = elements.keySet().iterator().next(); assertThat(element.getName()).isEqualTo("requires"); assertThat(element.getAttribute("field")).isEqualTo("model"); assertThat(element.getAttribute("filter")).contains("=entity)"); }
From source file:org.wisdom.ipojo.module.WisdomServiceVisitorTest.java
License:Apache License
@Test public void testOnlyService() { Reporter reporter = mock(Reporter.class); ComponentWorkbench workbench = mock(ComponentWorkbench.class); when(workbench.getType()).thenReturn(Type.getType(MyComponent.class)); when(workbench.getClassNode()).thenReturn(new ClassNode()); doAnswer(new Answer<Void>() { @Override//w w w . ja v a2 s.c o m public Void answer(InvocationOnMock invocation) throws Throwable { root = (Element) invocation.getArguments()[0]; return null; } }).when(workbench).setRoot(any(Element.class)); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { instance = (Element) invocation.getArguments()[0]; return null; } }).when(workbench).setInstance(any(Element.class)); WisdomServiceVisitor visitor = new WisdomServiceVisitor(workbench, reporter); visitor.visitEnd(); // Check the generated Component assertThat(root).isNotNull(); assertThat(root.getName()).isEqualTo("component"); assertThat(root.getAttribute("classname")).isEqualTo(MyComponent.class.getName()); // Check the Provides element assertThat(root.getElements("provides")).hasSize(1); // Check the Instance declaration assertThat(instance).isNotNull(); assertThat(instance.getAttribute("component")).isEqualTo(MyComponent.class.getName()); }
From source file:org.wisdom.ipojo.module.WisdomServiceVisitorTest.java
License:Apache License
@Test public void testServiceWithOneSpecification() { Reporter reporter = mock(Reporter.class); ComponentWorkbench workbench = mock(ComponentWorkbench.class); when(workbench.getType()).thenReturn(Type.getType(MyComponent.class)); when(workbench.getClassNode()).thenReturn(new ClassNode()); doAnswer(new Answer<Void>() { @Override//from w w w. j a v a 2 s . com public Void answer(InvocationOnMock invocation) throws Throwable { root = (Element) invocation.getArguments()[0]; return null; } }).when(workbench).setRoot(any(Element.class)); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { instance = (Element) invocation.getArguments()[0]; return null; } }).when(workbench).setInstance(any(Element.class)); WisdomServiceVisitor visitor = new WisdomServiceVisitor(workbench, reporter); AnnotationVisitor ann = visitor.visitArray("value"); ann.visit(null, Type.getType(Runnable.class)); ann.visitEnd(); visitor.visitEnd(); // Check the generated Component assertThat(root).isNotNull(); assertThat(root.getName()).isEqualTo("component"); assertThat(root.getAttribute("classname")).isEqualTo(MyComponent.class.getName()); // Check the Provides element assertThat(root.getElements("provides")).hasSize(1); assertThat(root.getElements("provides")[0].getAttribute("specifications")).isNotNull() .isEqualTo("{" + Runnable.class.getName() + "}"); // Check the Instance declaration assertThat(instance).isNotNull(); assertThat(instance.getAttribute("component")).isEqualTo(MyComponent.class.getName()); }
From source file:org.wisdom.ipojo.module.WisdomServiceVisitorTest.java
License:Apache License
@Test public void testServiceWithTwoSpecifications() { Reporter reporter = mock(Reporter.class); ComponentWorkbench workbench = mock(ComponentWorkbench.class); when(workbench.getType()).thenReturn(Type.getType(MyComponent.class)); when(workbench.getClassNode()).thenReturn(new ClassNode()); doAnswer(new Answer<Void>() { @Override/*from w w w .ja va2 s .c o m*/ public Void answer(InvocationOnMock invocation) throws Throwable { root = (Element) invocation.getArguments()[0]; return null; } }).when(workbench).setRoot(any(Element.class)); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { instance = (Element) invocation.getArguments()[0]; return null; } }).when(workbench).setInstance(any(Element.class)); WisdomServiceVisitor visitor = new WisdomServiceVisitor(workbench, reporter); AnnotationVisitor ann = visitor.visitArray("value"); ann.visit(null, Type.getType(Runnable.class)); ann.visit(null, Type.getType(List.class)); ann.visitEnd(); visitor.visitEnd(); // Check the generated Component assertThat(root).isNotNull(); assertThat(root.getName()).isEqualTo("component"); assertThat(root.getAttribute("classname")).isEqualTo(MyComponent.class.getName()); // Check the Provides element assertThat(root.getElements("provides")).hasSize(1); assertThat(root.getElements("provides")[0].getAttribute("specifications")).isNotNull() .isEqualTo("{" + Runnable.class.getName() + "," + List.class.getName() + "}"); // Check the Instance declaration assertThat(instance).isNotNull(); assertThat(instance.getAttribute("component")).isEqualTo(MyComponent.class.getName()); }
From source file:org.wisdom.ipojo.module.WisdomServiceVisitorTest.java
License:Apache License
@Test public void testWhenAnotherRootIsAlreadyDeclared() { Reporter reporter = mock(Reporter.class); ComponentWorkbench workbench = mock(ComponentWorkbench.class); // Set another root when(workbench.getRoot()).thenReturn(new Element("another", "root")); when(workbench.getType()).thenReturn(Type.getType(MyComponent.class)); when(workbench.getClassNode()).thenReturn(new ClassNode()); doAnswer(new Answer<Void>() { @Override/*w ww. j a v a 2s . c o m*/ public Void answer(InvocationOnMock invocation) throws Throwable { root = (Element) invocation.getArguments()[0]; return null; } }).when(workbench).setRoot(any(Element.class)); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { instance = (Element) invocation.getArguments()[0]; return null; } }).when(workbench).setInstance(any(Element.class)); WisdomServiceVisitor visitor = new WisdomServiceVisitor(workbench, reporter); visitor.visitEnd(); // Check that nothing is generated assertThat(root).isNull(); assertThat(instance).isNull(); }
From source file:org.wisdom.ipojo.module.WisdomViewVisitorTest.java
License:Apache License
@Test public void parseRegularView() { Reporter reporter = new SystemReporter(); ComponentWorkbench workbench = mock(ComponentWorkbench.class); when(workbench.getType()).thenReturn(Type.getType(MyComponent.class)); when(workbench.getClassNode()).thenReturn(new ClassNode()); when(workbench.getElements()).thenReturn(elements); FieldNode node = new FieldNode(Opcodes.ACC_PROTECTED, "template", Type.getDescriptor(Template.class), null, null);/* w ww .j ava2 s . c o m*/ WisdomViewVisitor visitor = new WisdomViewVisitor(workbench, reporter, node); visitor.visit("value", "index"); visitor.visitEnd(); assertThat(elements).hasSize(1); Element element = elements.keySet().iterator().next(); assertThat(element.getName()).isEqualTo("requires"); assertThat(element.getAttribute("field")).isEqualTo("template"); assertThat(element.getAttribute("filter")).contains("(name=index)"); }