@Test
 public void hasAndFindForPluginWithoutId() {
   Plugin plugin = getPluginWithoutId();
   Class<? extends Plugin> pluginType = plugin.getClass();
   addWithType(pluginType);
   assertThat(getPluginContainer().hasPlugin(pluginType.getName()), equalTo(true));
   assertThat(getPluginContainer().hasPlugin(pluginType), equalTo(true));
   assertThat(getPluginContainer().findPlugin(pluginType), sameInstance(plugin));
   assertThat(getPluginContainer().findPlugin(pluginType.getName()), sameInstance(plugin));
 }
  @Test
  public void refToFragmentOfAnotherSchemaIsReadSuccessfully() throws NoSuchMethodException {

    Class<?> aClass = fragmentRefsClass.getMethod("getFragmentOfA").getReturnType();

    assertThat(aClass.getName(), is("com.example.AdditionalPropertyValue"));
  }
Esempio n. 3
0
  @Test
  public void nestedSelfRefsInStringContentWithoutParentFile()
      throws NoSuchMethodException, ClassNotFoundException, IOException {

    String schemaContents =
        IOUtils.toString(
            CodeGenerationHelper.class.getResource("/schema/ref/nestedSelfRefsReadAsString.json"));
    JCodeModel codeModel = new JCodeModel();
    new SchemaMapper().generate(codeModel, "NestedSelfRefsInString", "com.example", schemaContents);

    codeModel.build(schemaRule.getGenerateDir());

    ClassLoader classLoader = schemaRule.compile();

    Class<?> nestedSelfRefs = classLoader.loadClass("com.example.NestedSelfRefsInString");
    assertThat(
        nestedSelfRefs.getMethod("getThings").getReturnType().getSimpleName(), equalTo("List"));

    Class<?> listEntryType =
        (Class<?>)
            ((ParameterizedType) nestedSelfRefs.getMethod("getThings").getGenericReturnType())
                .getActualTypeArguments()[0];
    assertThat(listEntryType.getName(), equalTo("com.example.Thing"));

    Class<?> thingClass = classLoader.loadClass("com.example.Thing");
    assertThat(
        thingClass.getMethod("getNamespace").getReturnType().getSimpleName(), equalTo("String"));
    assertThat(thingClass.getMethod("getName").getReturnType().getSimpleName(), equalTo("String"));
    assertThat(
        thingClass.getMethod("getVersion").getReturnType().getSimpleName(), equalTo("String"));
  }
Esempio n. 4
0
  @Test
  public void selfRefUsedInAPropertyIsReadSuccessfully() throws NoSuchMethodException {

    Class<?> aClass = selfRefsClass.getMethod("getChildOfSelf").getReturnType();

    assertThat(aClass.getName(), is("com.example.SelfRefs"));
  }
  @Test
  public void refToFragmentOfSelfIsReadSuccessfully() throws NoSuchMethodException {

    Class<?> aClass = fragmentRefsClass.getMethod("getFragmentOfSelf").getReturnType();

    assertThat(aClass.getName(), is("com.example.A"));
    assertThat(aClass.getMethods(), hasItemInArray(hasProperty("name", equalTo("getPropertyOfA"))));
  }
 @Test
 public void addPluginWithoutId() {
   Class<? extends Plugin> type = getPluginWithoutId().getClass();
   Plugin addedPlugin = addWithType(type);
   assertThat(getPluginWithoutId(), sameInstance(addedPlugin));
   assertThat(addedPlugin, sameInstance((Plugin) addWithType(type)));
   assertThat(addedPlugin, sameInstance(getPluginContainer().findByName(type.getName())));
 }
Esempio n. 7
0
  @Test
  public void selfRefUsedAsArrayItemsIsReadSuccessfully() throws NoSuchMethodException {

    Type listOfAType = selfRefsClass.getMethod("getArrayOfSelf").getGenericReturnType();
    Class<?> listEntryClass =
        (Class<?>) ((ParameterizedType) listOfAType).getActualTypeArguments()[0];

    assertThat(listEntryClass.getName(), is("com.example.SelfRefs"));
  }
Esempio n. 8
0
  @Test
  public void selfRefUsedForAdditionalPropertiesIsReadSuccessfully() throws NoSuchMethodException {

    Type additionalPropertiesType =
        selfRefsClass.getMethod("getAdditionalProperties").getGenericReturnType();
    Class<?> mapEntryClass =
        (Class<?>) ((ParameterizedType) additionalPropertiesType).getActualTypeArguments()[1];

    assertThat(mapEntryClass.getName(), is("com.example.SelfRefs"));
  }
 private File createFileForClass(Class<TestFakeProduct> clazz) throws IOException {
   File destFile = InfinitestTestUtils.getFileForClass(altClassDir, clazz.getName());
   assertTrue(destFile.getParentFile().mkdirs());
   assertTrue(destFile.createNewFile());
   return destFile;
 }
 private AnnotationAttributes findMergedAnnotationAttributes(
     AnnotatedElement element, Class<? extends Annotation> annotationType) {
   Assert.notNull(annotationType, "annotationType must not be null");
   return AnnotatedElementUtils.findMergedAnnotationAttributes(
       element, annotationType.getName(), false, false);
 }
 void setTracker(Class<? extends ExecutionTracker> tracker) {
   this.replacement.put("tracker", tracker.getName());
 }