Java Code Examples for com.sun.codemodel.JDefinedClass#annotate()
The following examples show how to use
com.sun.codemodel.JDefinedClass#annotate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityUtilsTest.java From jpa-unit with Apache License 2.0 | 6 votes |
@Test public void testGetEntityClassFromNodeLabelsHavingTheLabelDeclaredByTheTableAnnotationWithoutInheritance() throws Exception { final String simpleClassName = "EntityClass"; final String nodeLabel = "ENTITY_CLASS"; final JPackage jp = jCodeModel.rootPackage(); final JDefinedClass jClass = jp._class(JMod.PUBLIC, simpleClassName); jClass.annotate(Entity.class); jClass.annotate(Table.class).param("name", nodeLabel); buildModel(testFolder.getRoot(), jCodeModel); compileModel(testFolder.getRoot()); final Class<?> entityClass = loadClass(testFolder.getRoot(), jClass.name()); final Class<?> clazz = EntityUtils.getEntityClassFromNodeLabels(Arrays.asList(nodeLabel), Arrays.asList(entityClass)); assertThat(clazz, equalTo(entityClass)); }
Example 2
Source File: GraphElementFactoryTest.java From jpa-unit with Apache License 2.0 | 6 votes |
@BeforeClass public static void generateTestModel() throws Exception { final JCodeModel jCodeModel = new JCodeModel(); final JPackage jp = jCodeModel.rootPackage(); final JDefinedClass jClass = jp._class(JMod.PUBLIC, "A"); jClass.annotate(Entity.class); jClass.field(JMod.PRIVATE, Long.class, "id").annotate(Id.class); jClass.field(JMod.PRIVATE, String.class, "value"); buildModel(testFolder.getRoot(), jCodeModel); compileModel(testFolder.getRoot()); entityAClass = loadClass(testFolder.getRoot(), jClass.name()); }
Example 3
Source File: EntityUtilsTest.java From jpa-unit with Apache License 2.0 | 6 votes |
@Test public void testGetNamesOfIdPropertiesFromASingleClassHavingAMethodAnnotatedWithId() throws Exception { // GIVEN final String simpleClassName = "EntityClass"; final String idPropertyName = "key"; final JPackage jp = jCodeModel.rootPackage(); final JDefinedClass jClass = jp._class(JMod.PUBLIC, simpleClassName); jClass.annotate(Entity.class); jClass.method(JMod.PUBLIC, jCodeModel.VOID, "getKey").annotate(Id.class); buildModel(testFolder.getRoot(), jCodeModel); compileModel(testFolder.getRoot()); final Class<?> entityClass = loadClass(testFolder.getRoot(), jClass.name()); // WHEN final List<String> namesOfIdProperties = EntityUtils.getNamesOfIdProperties(entityClass); // THEN assertThat(namesOfIdProperties.size(), equalTo(1)); assertThat(namesOfIdProperties, hasItem(idPropertyName)); }
Example 4
Source File: EntityUtilsTest.java From jpa-unit with Apache License 2.0 | 6 votes |
@Test public void testGetNamesOfIdPropertiesFromASingleClassHavingAFieldAnnotatedWithId() throws Exception { // GIVEN final String simpleClassName = "EntityClass"; final String idPropertyName = "key"; final JPackage jp = jCodeModel.rootPackage(); final JDefinedClass jClass = jp._class(JMod.PUBLIC, simpleClassName); jClass.annotate(Entity.class); jClass.field(JMod.PRIVATE, String.class, idPropertyName).annotate(Id.class); buildModel(testFolder.getRoot(), jCodeModel); compileModel(testFolder.getRoot()); final Class<?> entityClass = loadClass(testFolder.getRoot(), jClass.name()); // WHEN final List<String> namesOfIdProperties = EntityUtils.getNamesOfIdProperties(entityClass); // THEN assertThat(namesOfIdProperties.size(), equalTo(1)); assertThat(namesOfIdProperties, hasItem(idPropertyName)); }
Example 5
Source File: ImplementationBuilder.java From aem-component-generator with Apache License 2.0 | 6 votes |
private void addSlingAnnotations(JDefinedClass jDefinedClass, JClass adapterClass, String resourceType) { JAnnotationUse jAUse = jDefinedClass.annotate(codeModel.ref(Model.class)); JAnnotationArrayMember adaptablesArray = jAUse.paramArray("adaptables"); for (String adaptable : adaptables) { if ("resource".equalsIgnoreCase(adaptable)) { adaptablesArray.param(codeModel.ref(Resource.class)); } if ("request".equalsIgnoreCase(adaptable)) { adaptablesArray.param(codeModel.ref(SlingHttpServletRequest.class)); } } if (this.isAllowExporting) { jAUse.paramArray("adapters").param(adapterClass).param(codeModel.ref(ComponentExporter.class)); } else { jAUse.param("adapters", adapterClass); } if (StringUtils.isNotBlank(resourceType)) { jAUse.param("resourceType", resourceType); } if (this.isAllowExporting) { jAUse = jDefinedClass.annotate(codeModel.ref(Exporter.class)); jAUse.param("name", codeModel.ref(ExporterConstants.class).staticRef(SLING_MODEL_EXPORTER_NAME)); jAUse.param("extensions", codeModel.ref(ExporterConstants.class).staticRef(SLING_MODEL_EXTENSION)); } }
Example 6
Source File: JpaUnitRunnerTest.java From jpa-unit with Apache License 2.0 | 5 votes |
@Test public void testClassWithPersistenceUnitWithKonfiguredUnitNameSpecified() throws Exception { // GIVEN final JCodeModel jCodeModel = new JCodeModel(); final JPackage jp = jCodeModel.rootPackage(); final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest"); final JAnnotationUse jAnnotationUse = jClass.annotate(RunWith.class); jAnnotationUse.param("value", JpaUnitRunner.class); final JFieldVar emField = jClass.field(JMod.PRIVATE, EntityManagerFactory.class, "emf"); final JAnnotationUse jAnnotation = emField.annotate(PersistenceUnit.class); jAnnotation.param("unitName", "test-unit-1"); final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod"); jMethod.annotate(Test.class); buildModel(testFolder.getRoot(), jCodeModel); compileModel(testFolder.getRoot()); final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name()); final JpaUnitRunner runner = new JpaUnitRunner(cut); final RunListener listener = mock(RunListener.class); final RunNotifier notifier = new RunNotifier(); notifier.addListener(listener); // WHEN runner.run(notifier); // THEN final ArgumentCaptor<Description> descriptionCaptor = ArgumentCaptor.forClass(Description.class); verify(listener).testStarted(descriptionCaptor.capture()); assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest")); assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod")); verify(listener).testFinished(descriptionCaptor.capture()); assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest")); assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod")); }
Example 7
Source File: SpringValidatedClassAnnotationRule.java From springmvc-raml-plugin with Apache License 2.0 | 5 votes |
@Override public JAnnotationUse apply(ApiResourceMetadata controllerMetadata, JDefinedClass generatableType) { if (Config.getPojoConfig().isIncludeJsr303Annotations()) { return generatableType.annotate(Validated.class); } return null; }
Example 8
Source File: JpaUnitRunnerTest.java From jpa-unit with Apache License 2.0 | 5 votes |
@Test public void testClassWithPersistenceUnitFieldOfWrongType() throws Exception { // GIVEN final JCodeModel jCodeModel = new JCodeModel(); final JPackage jp = jCodeModel.rootPackage(); final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest"); final JAnnotationUse jAnnotationUse = jClass.annotate(RunWith.class); jAnnotationUse.param("value", JpaUnitRunner.class); final JFieldVar emField = jClass.field(JMod.PRIVATE, EntityManager.class, "emf"); emField.annotate(PersistenceUnit.class); final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod"); jMethod.annotate(Test.class); buildModel(testFolder.getRoot(), jCodeModel); compileModel(testFolder.getRoot()); final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name()); final RunListener listener = mock(RunListener.class); final RunNotifier notifier = new RunNotifier(); notifier.addListener(listener); final JpaUnitRunner runner = new JpaUnitRunner(cut); // WHEN runner.run(notifier); // THEN final ArgumentCaptor<Failure> failureCaptor = ArgumentCaptor.forClass(Failure.class); verify(listener).testFailure(failureCaptor.capture()); final Failure failure = failureCaptor.getValue(); assertThat(failure.getException().getClass(), equalTo(IllegalArgumentException.class)); assertThat(failure.getException().getMessage(), containsString("annotated with @PersistenceUnit is not of type EntityManagerFactory")); }
Example 9
Source File: EntityUtilsTest.java From jpa-unit with Apache License 2.0 | 5 votes |
@Test public void testGetNamesOfIdPropertiesFromASingleClassHavingAFieldAnnotatedWithEmbeddedId() throws Exception { // GIVEN final String simpleClassName = "EntityClass"; final String compositeIdPropertyName = "compositeKey"; final String id1PropertyName = "key1"; final String id2PropertyName = "key2"; final JPackage jp = jCodeModel.rootPackage(); final JDefinedClass jIdTypeClass = jp._class(JMod.PUBLIC, "IdType"); jIdTypeClass.annotate(Embeddable.class); jIdTypeClass.field(JMod.PRIVATE, Integer.class, id1PropertyName); jIdTypeClass.field(JMod.PRIVATE, String.class, id2PropertyName); final JDefinedClass jClass = jp._class(JMod.PUBLIC, simpleClassName); jClass.annotate(Entity.class); jClass.field(JMod.PRIVATE, jIdTypeClass, compositeIdPropertyName).annotate(EmbeddedId.class); buildModel(testFolder.getRoot(), jCodeModel); compileModel(testFolder.getRoot()); final Class<?> entityClass = loadClass(testFolder.getRoot(), jClass.name()); // WHEN final List<String> namesOfIdProperties = EntityUtils.getNamesOfIdProperties(entityClass); // THEN assertThat(namesOfIdProperties.size(), equalTo(2)); assertThat(namesOfIdProperties, hasItems(compositeIdPropertyName + "." + id1PropertyName, compositeIdPropertyName + "." + id2PropertyName)); }
Example 10
Source File: EntityUtilsTest.java From jpa-unit with Apache License 2.0 | 5 votes |
@Test public void testGetNamesOfIdPropertiesFromAClassHierarchyHavingAMethodAnnotatedWithId() throws Exception { // GIVEN final String simpleClassNameBase = "EntityClass"; final String simpleClassNameB = "SubEntityClass"; final String idPropertyName = "key"; final JPackage jp = jCodeModel.rootPackage(); final JDefinedClass jBaseClass = jp._class(JMod.PUBLIC, simpleClassNameBase); jBaseClass.annotate(Entity.class); jBaseClass.annotate(Inheritance.class).param("strategy", InheritanceType.TABLE_PER_CLASS); jBaseClass.method(JMod.PUBLIC, jCodeModel.VOID, "getKey").annotate(Id.class); final JDefinedClass jSubclass = jp._class(JMod.PUBLIC, simpleClassNameB)._extends(jBaseClass); jSubclass.annotate(Entity.class); buildModel(testFolder.getRoot(), jCodeModel); compileModel(testFolder.getRoot()); final Class<?> subClass = loadClass(testFolder.getRoot(), jSubclass.name()); // WHEN final List<String> namesOfIdProperties = EntityUtils.getNamesOfIdProperties(subClass); // THEN assertThat(namesOfIdProperties.size(), equalTo(1)); assertThat(namesOfIdProperties, hasItem(idPropertyName)); }
Example 11
Source File: EntityUtilsTest.java From jpa-unit with Apache License 2.0 | 5 votes |
@Test public void testGetEntityClassFromNodeLabelsHavingTheLabelDeclaredByTheTableAnnotationWithJoinedInheritance() throws Exception { final String simpleClassNameBase = "EntityClass"; final String simpleClassNameA = "SubEntityClassA"; final String simpleClassNameB = "SubEntityClassB"; final String nodeLabelBase = "ENTITY_CLASS"; final String nodeLabelA = "ENTITY_CLASS_A"; final String nodeLabelB = "ENTITY_CLASS_B"; final JPackage jp = jCodeModel.rootPackage(); final JDefinedClass jBaseClass = jp._class(JMod.PUBLIC, simpleClassNameBase); jBaseClass.annotate(Entity.class); jBaseClass.annotate(Table.class).param("name", nodeLabelBase); jBaseClass.annotate(Inheritance.class).param("strategy", InheritanceType.JOINED); final JDefinedClass jSubclassA = jp._class(JMod.PUBLIC, simpleClassNameA)._extends(jBaseClass); jSubclassA.annotate(Entity.class); jSubclassA.annotate(Table.class).param("name", nodeLabelA); final JDefinedClass jSubclassB = jp._class(JMod.PUBLIC, simpleClassNameB)._extends(jBaseClass); jSubclassB.annotate(Entity.class); jSubclassB.annotate(Table.class).param("name", nodeLabelB); buildModel(testFolder.getRoot(), jCodeModel); compileModel(testFolder.getRoot()); final Class<?> baseClass = loadClass(testFolder.getRoot(), jBaseClass.name()); final Class<?> subClassA = loadClass(testFolder.getRoot(), jSubclassA.name()); final Class<?> subClassB = loadClass(testFolder.getRoot(), jSubclassB.name()); final Class<?> clazz = EntityUtils.getEntityClassFromNodeLabels(Arrays.asList(nodeLabelA), Arrays.asList(baseClass, subClassA, subClassB)); assertThat(clazz, equalTo(subClassA)); }
Example 12
Source File: JpaUnitRunnerTest.java From jpa-unit with Apache License 2.0 | 5 votes |
@Test public void testClassWithMultiplePersistenceUnitFields() throws Exception { // GIVEN final JCodeModel jCodeModel = new JCodeModel(); final JPackage jp = jCodeModel.rootPackage(); final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest"); final JAnnotationUse jAnnotationUse = jClass.annotate(RunWith.class); jAnnotationUse.param("value", JpaUnitRunner.class); final JFieldVar emf1Field = jClass.field(JMod.PRIVATE, EntityManagerFactory.class, "emf1"); emf1Field.annotate(PersistenceUnit.class); final JFieldVar emf2Field = jClass.field(JMod.PRIVATE, EntityManagerFactory.class, "emf2"); emf2Field.annotate(PersistenceUnit.class); final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod"); jMethod.annotate(Test.class); buildModel(testFolder.getRoot(), jCodeModel); compileModel(testFolder.getRoot()); final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name()); final RunListener listener = mock(RunListener.class); final RunNotifier notifier = new RunNotifier(); notifier.addListener(listener); final JpaUnitRunner runner = new JpaUnitRunner(cut); // WHEN runner.run(notifier); // THEN final ArgumentCaptor<Failure> failureCaptor = ArgumentCaptor.forClass(Failure.class); verify(listener).testFailure(failureCaptor.capture()); final Failure failure = failureCaptor.getValue(); assertThat(failure.getException().getClass(), equalTo(IllegalArgumentException.class)); assertThat(failure.getException().getMessage(), containsString("Only single field is allowed")); }
Example 13
Source File: SpringRequestMappingClassAnnotationRule.java From springmvc-raml-plugin with Apache License 2.0 | 5 votes |
@Override public JAnnotationUse apply(ApiResourceMetadata controllerMetadata, JDefinedClass generatableType) { JAnnotationUse requestMapping = generatableType.annotate(RequestMapping.class); requestMapping.param("value", controllerMetadata.getControllerUrl()); try { String mediaType = generateMediaType(controllerMetadata); if (mediaType != null) { requestMapping.param("produces", mediaType); } } catch (Exception e) { throw new InvalidCodeModelException("Your model contains an invalid media type", e); } return requestMapping; }
Example 14
Source File: EntityUtilsTest.java From jpa-unit with Apache License 2.0 | 5 votes |
@Test public void testGetEntityClassFromNodeLabelsHavingTheLabelDeclaredByTheTableAnnotationWithSingleTableInheritance() throws Exception { final String simpleClassNameBase = "EntityClass"; final String simpleClassNameA = "SubEntityClassA"; final String simpleClassNameB = "SubEntityClassB"; final String nodeLabel = "ENTITY_CLASS"; final JPackage jp = jCodeModel.rootPackage(); final JDefinedClass jBaseClass = jp._class(JMod.PUBLIC, simpleClassNameBase); jBaseClass.annotate(Entity.class); jBaseClass.annotate(Table.class).param("name", nodeLabel); jBaseClass.annotate(Inheritance.class).param("strategy", InheritanceType.SINGLE_TABLE); jBaseClass.annotate(DiscriminatorColumn.class).param("name", "TYPE"); final JDefinedClass jSubclassA = jp._class(JMod.PUBLIC, simpleClassNameA)._extends(jBaseClass); jSubclassA.annotate(Entity.class); jSubclassA.annotate(DiscriminatorValue.class).param("value", "A"); final JDefinedClass jSubclassB = jp._class(JMod.PUBLIC, simpleClassNameB)._extends(jBaseClass); jSubclassB.annotate(Entity.class); jSubclassB.annotate(DiscriminatorValue.class).param("value", "B"); buildModel(testFolder.getRoot(), jCodeModel); compileModel(testFolder.getRoot()); final Class<?> baseClass = loadClass(testFolder.getRoot(), jBaseClass.name()); final Class<?> subClassA = loadClass(testFolder.getRoot(), jSubclassA.name()); final Class<?> subClassB = loadClass(testFolder.getRoot(), jSubclassB.name()); final Class<?> clazz = EntityUtils.getEntityClassFromNodeLabels(Arrays.asList(nodeLabel), Arrays.asList(baseClass, subClassA, subClassB)); assertThat(clazz, equalTo(baseClass)); }
Example 15
Source File: JpaUnitRunnerTest.java From jpa-unit with Apache License 2.0 | 5 votes |
@Test public void testClassWithPersistenceContextFieldOfWrongType() throws Exception { // GIVEN final JCodeModel jCodeModel = new JCodeModel(); final JPackage jp = jCodeModel.rootPackage(); final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest"); final JAnnotationUse jAnnotationUse = jClass.annotate(RunWith.class); jAnnotationUse.param("value", JpaUnitRunner.class); final JFieldVar emField = jClass.field(JMod.PRIVATE, EntityManagerFactory.class, "em"); emField.annotate(PersistenceContext.class); final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod"); jMethod.annotate(Test.class); buildModel(testFolder.getRoot(), jCodeModel); compileModel(testFolder.getRoot()); final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name()); final RunListener listener = mock(RunListener.class); final RunNotifier notifier = new RunNotifier(); notifier.addListener(listener); final JpaUnitRunner runner = new JpaUnitRunner(cut); // WHEN runner.run(notifier); // THEN final ArgumentCaptor<Failure> failureCaptor = ArgumentCaptor.forClass(Failure.class); verify(listener).testFailure(failureCaptor.capture()); final Failure failure = failureCaptor.getValue(); assertThat(failure.getException().getClass(), equalTo(IllegalArgumentException.class)); assertThat(failure.getException().getMessage(), containsString("annotated with @PersistenceContext is not of type EntityManager")); }
Example 16
Source File: JpaUnitRunnerTest.java From jpa-unit with Apache License 2.0 | 5 votes |
@Test public void testClassWithPersistenceContextWithKonfiguredUnitNameSpecified() throws Exception { // GIVEN final JCodeModel jCodeModel = new JCodeModel(); final JPackage jp = jCodeModel.rootPackage(); final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest"); final JAnnotationUse jAnnotationUse = jClass.annotate(RunWith.class); jAnnotationUse.param("value", JpaUnitRunner.class); final JFieldVar emField = jClass.field(JMod.PRIVATE, EntityManager.class, "em"); final JAnnotationUse jAnnotation = emField.annotate(PersistenceContext.class); jAnnotation.param("unitName", "test-unit-1"); final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod"); jMethod.annotate(Test.class); buildModel(testFolder.getRoot(), jCodeModel); compileModel(testFolder.getRoot()); final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name()); final JpaUnitRunner runner = new JpaUnitRunner(cut); final RunListener listener = mock(RunListener.class); final RunNotifier notifier = new RunNotifier(); notifier.addListener(listener); // WHEN runner.run(notifier); // THEN final ArgumentCaptor<Description> descriptionCaptor = ArgumentCaptor.forClass(Description.class); verify(listener).testStarted(descriptionCaptor.capture()); assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest")); assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod")); verify(listener).testFinished(descriptionCaptor.capture()); assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest")); assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod")); }
Example 17
Source File: KubernetesCoreTypeAnnotator.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public void propertyOrder(JDefinedClass clazz, JsonNode propertiesNode) { JAnnotationArrayMember annotationValue = clazz.annotate(JsonPropertyOrder.class).paramArray(ANNOTATION_VALUE); annotationValue.param(API_VERSION); annotationValue.param(KIND); annotationValue.param(METADATA); for (Iterator<String> properties = propertiesNode.fieldNames(); properties.hasNext();) { String next = properties.next(); if (!next.equals(API_VERSION) && !next.equals(KIND) && !next.equals(METADATA)) { annotationValue.param(next); } } clazz.annotate(ToString.class); clazz.annotate(EqualsAndHashCode.class); processBuildable(clazz); if (clazz.fields().containsKey(KIND) && clazz.fields().containsKey(METADATA)) { String resourceName; if (clazz.name().endsWith("List")) { resourceName = clazz.name().substring(0, clazz.name().length() - 4); pendingLists.put(resourceName, clazz); } else { resourceName = clazz.name(); pendingResources.put(clazz.name(), clazz); } if (pendingResources.containsKey(resourceName) && pendingLists.containsKey(resourceName)) { JDefinedClass resourceClass = pendingResources.get(resourceName); JDefinedClass resourceListClass = pendingLists.get(resourceName); String apiVersion = propertiesNode.get(API_VERSION).get("default").toString().replaceAll(Pattern.quote("\""), ""); String apiGroup = ""; if (apiVersion.contains("/")) { apiGroup = apiVersion.substring(0, apiVersion.lastIndexOf('/')); apiVersion = apiVersion.substring(apiGroup.length() + 1); } String packageSuffix = getPackageSuffix(apiVersion); resourceClass.annotate(ApiVersion.class).param(ANNOTATION_VALUE, apiVersion); resourceClass.annotate(ApiGroup.class).param(ANNOTATION_VALUE, apiGroup); resourceClass.annotate(PackageSuffix.class).param(ANNOTATION_VALUE, packageSuffix); resourceListClass.annotate(ApiVersion.class).param(ANNOTATION_VALUE, apiVersion); resourceListClass.annotate(ApiGroup.class).param(ANNOTATION_VALUE, apiGroup); resourceListClass.annotate(PackageSuffix.class).param(ANNOTATION_VALUE, packageSuffix); pendingLists.remove(resourceName); pendingResources.remove(resourceName); addClassesToPropertyFiles(resourceClass); } } }
Example 18
Source File: LombokCommand.java From jaxb-lombok-plugin with MIT License | 4 votes |
@Override public void editGeneratedClass(JDefinedClass generatedClass) { for (Class<? extends Annotation> lombokAnnotation : lombokAnnotations) { generatedClass.annotate(lombokAnnotation); } }
Example 19
Source File: ClassAnnotationRule.java From springmvc-raml-plugin with Apache License 2.0 | 4 votes |
@Override public JAnnotationUse apply(ApiResourceMetadata controllerMetadata, JDefinedClass generatableType) { return generatableType.annotate(annotationType); }
Example 20
Source File: JpaUnitRunnerTest.java From jpa-unit with Apache License 2.0 | 4 votes |
@Test public void testClassWithPersistenceContextWithWithOverwrittenConfiguration() throws Exception { // GIVEN final JCodeModel jCodeModel = new JCodeModel(); final JPackage jp = jCodeModel.rootPackage(); final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest"); final JAnnotationUse jAnnotationUse = jClass.annotate(RunWith.class); jAnnotationUse.param("value", JpaUnitRunner.class); final JFieldVar emField = jClass.field(JMod.PRIVATE, EntityManager.class, "em"); final JAnnotationUse jAnnotation = emField.annotate(PersistenceContext.class); jAnnotation.param("unitName", "test-unit-1"); final JAnnotationArrayMember propArray = jAnnotation.paramArray("properties"); propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.url").param("value", "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"); propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.driver").param("value", "org.h2.Driver"); propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.password").param("value", "test"); propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.user").param("value", "test"); final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod"); jMethod.annotate(Test.class); buildModel(testFolder.getRoot(), jCodeModel); compileModel(testFolder.getRoot()); final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name()); final JpaUnitRunner runner = new JpaUnitRunner(cut); final RunListener listener = mock(RunListener.class); final RunNotifier notifier = new RunNotifier(); notifier.addListener(listener); // WHEN runner.run(notifier); // THEN final ArgumentCaptor<Description> descriptionCaptor = ArgumentCaptor.forClass(Description.class); verify(listener).testStarted(descriptionCaptor.capture()); assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest")); assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod")); verify(listener).testFinished(descriptionCaptor.capture()); assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest")); assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod")); }