private ThriftStructMetadata testStructMetadataBuild( Class<?> structClass, int expectedConstructorParameters, int expectedMethodInjections) throws Exception { return testMetadataBuild( ThriftStructMetadataBuilder.class, structClass, expectedConstructorParameters, expectedMethodInjections); }
@Test public void testBean() throws Exception { ThriftStructMetadata metadata = testStructMetadataBuild(BonkBean.class, 0, 2); verifyParameterInjection(metadata, 1, "message", 0); verifyMethodExtraction(metadata, 1, "message", "getMessage"); verifyParameterInjection(metadata, 2, "type", 0); verifyMethodExtraction(metadata, 2, "type", "getType"); }
@Test public void testField() throws Exception { ThriftStructMetadata metadata = testStructMetadataBuild(BonkField.class, 0, 0); verifyFieldInjection(metadata, 1, "message"); verifyFieldExtraction(metadata, 1, "message"); verifyFieldInjection(metadata, 2, "type"); verifyFieldExtraction(metadata, 2, "type"); }
private <T extends AbstractThriftMetadataBuilder> ThriftStructMetadata testMetadataBuild( Class<T> metadataBuilderType, Class<?> structClass, int expectedConstructorParameters, int expectedMethodInjections) throws Exception { ThriftStructMetadata metadata = buildMetadata(structClass, metadataBuilderType); assertNotNull(metadata); assertTrue( MetadataType.UNION == metadata.getMetadataType() || MetadataType.STRUCT == metadata.getMetadataType()); verifyField(metadata, 1, "message"); verifyField(metadata, 2, "type"); ThriftConstructorInjection constructorInjection = metadata.getConstructorInjection().get(); assertNotNull(constructorInjection); assertEquals(constructorInjection.getParameters().size(), expectedConstructorParameters); assertEquals(metadata.getMethodInjections().size(), expectedMethodInjections); return metadata; }
@Test(expectedExceptions = MetadataErrorException.class) public void testFieldWithConflictingIdlAnnotationMap() throws Exception { /** * Single field with conflicting IDL annotation maps on setter vs getter: should fail */ testStructMetadataBuild(BeanWIthConflictingIdlAnnotationMapsForField.class, 0, 1); }
@Test public void testUnionWithIdlAnnotationsMap() throws Exception { ThriftStructMetadata metadata = testUnionMetadataBuild(UnionWithIdlAnnotations.class, 0, 2); Map<String, String> idlAnnotations = metadata.getIdlAnnotations(); assertEquals(idlAnnotations.size(), 2); assertEquals(idlAnnotations.get("testkey1"), "testvalue1"); assertEquals(idlAnnotations.get("testkey2"), "testvalue2"); }
@Test public void testStructWithIdlAnnotationsMap() throws Exception { ThriftStructMetadata metadata = testStructMetadataBuild(StructWithIdlAnnotations.class, 0, 0); Map<String, String> idlAnnotations = metadata.getIdlAnnotations(); assertEquals(idlAnnotations.size(), 2); assertEquals(idlAnnotations.get("testkey1"), "testvalue1"); assertEquals(idlAnnotations.get("testkey2"), "testvalue2"); }
@Test public void testConstructor() throws Exception { ThriftStructMetadata metadata = testStructMetadataBuild(BonkConstructor.class, 2, 0); verifyParameterInjection(metadata, 1, "message", 0); verifyMethodExtraction(metadata, 1, "message", "getMessage"); verifyParameterInjection(metadata, 2, "type", 1); verifyMethodExtraction(metadata, 2, "type", "getType"); }
@Test public void testExceptionWithIdlAnnotationsMap() throws Exception { ThriftStructMetadata metadata = testStructMetadataBuild(ExceptionWithIdlAnnotations.class, 2, 0); Map<String, String> idlAnnotations = metadata.getIdlAnnotations(); assertEquals(idlAnnotations.size(), 1); assertEquals(idlAnnotations.get("message"), "message"); }
private ThriftStructMetadata testUnionMetadataBuild( Class<?> structClass, int expectedConstructorParameters, int expectedMethodInjections) throws Exception { return testMetadataBuild( ThriftUnionMetadataBuilder.class, structClass, expectedConstructorParameters, expectedMethodInjections); }
@Test public void testMethod() throws Exception { ThriftStructMetadata metadata = testStructMetadataBuild(BonkMethod.class, 0, 1); verifyParameterInjection(metadata, 1, "message", 0); verifyMethodExtraction(metadata, 1, "message", "getMessage"); verifyParameterInjection(metadata, 2, "type", 1); verifyMethodExtraction(metadata, 2, "type", "getType"); }
@Test public void testFieldWithOneIdlAnnotationMap() throws Exception { /** * Single field with IDL annotation map on getter, but not on setter: should be okay */ ThriftStructMetadata metadata = testStructMetadataBuild(BeanWithOneIdlAnnotationMapForField.class, 0, 1); Map<String, String> idlAnnotations = metadata.getField(2).getIdlAnnotations(); assertEquals(idlAnnotations.size(), 2); assertEquals(idlAnnotations.get("testkey1"), "testvalue1"); assertEquals(idlAnnotations.get("testkey2"), "testvalue2"); }
@Test public void testBuilder() throws Exception { ThriftStructMetadata metadata = testStructMetadataBuild(BonkBuilder.class, 0, 2); verifyParameterInjection(metadata, 1, "message", 0); verifyMethodExtraction(metadata, 1, "message", "getMessage"); verifyParameterInjection(metadata, 2, "type", 0); verifyMethodExtraction(metadata, 2, "type", "getType"); }
@Test public void testFieldWithMatchingIdlAnnotationMaps() throws Exception { /** * Single field with matching IDL annotation maps on setter vs getter: should be okay */ ThriftStructMetadata metadata = testStructMetadataBuild(BeanWithMatchingIdlAnnotationsMapsForField.class, 0, 1); Map<String, String> idlAnnotations = metadata.getField(2).getIdlAnnotations(); assertEquals(idlAnnotations.size(), 2); assertEquals(idlAnnotations.get("testkey1"), "testvalue1"); assertEquals(idlAnnotations.get("testkey2"), "testvalue2"); }