@Test
    public void givenClass_whenAddMember() throws Exception {

      // given
      final ApplicationFeatureId classId = ApplicationFeatureId.newClass("com.mycompany.Bar");
      final ApplicationFeatureId propertyId =
          ApplicationFeatureId.newMember("com.mycompany.Bar", "foo");
      final ApplicationFeatureId actionId =
          ApplicationFeatureId.newMember("com.mycompany.Bar", "boz");

      final ApplicationFeature classFeature = new ApplicationFeature(classId);
      final ApplicationFeature propertyFeature = new ApplicationFeature(propertyId);
      propertyFeature.setMemberType(ApplicationMemberType.PROPERTY);
      final ApplicationFeature actionFeature = new ApplicationFeature(actionId);
      actionFeature.setMemberType(ApplicationMemberType.ACTION);

      classFeature.addToMembers(propertyId, ApplicationMemberType.PROPERTY);
      classFeature.addToMembers(actionId, ApplicationMemberType.ACTION);

      ApplicationClass applicationClass = new ApplicationClass(classId);
      applicationClass.applicationFeatureRepository = mockApplicationFeatureRepository;
      applicationClass.container = mockContainer;

      // then
      context.checking(
          new Expectations() {
            {
              allowing(mockApplicationFeatureRepository).findFeature(classId);
              will(returnValue(classFeature));

              allowing(mockApplicationFeatureRepository).findFeature(propertyId);
              will(returnValue(propertyFeature));

              allowing(mockApplicationFeatureRepository).findFeature(actionId);
              will(returnValue(actionFeature));

              oneOf(mockContainer)
                  .newViewModelInstance(
                      ApplicationClassProperty.class, propertyId.asEncodedString());
              will(returnValue(new ApplicationClassProperty(propertyId)));

              oneOf(mockContainer)
                  .newViewModelInstance(ApplicationClassAction.class, actionId.asEncodedString());
              will(returnValue(new ApplicationClassAction(actionId)));
            }
          });

      // when
      final List<ApplicationClassProperty> properties = applicationClass.getProperties();

      // then
      assertThat(properties.size(), is(1));

      // when
      final List<ApplicationClassAction> actions = applicationClass.getActions();

      // then
      assertThat(actions.size(), is(1));
    }
    @Test
    public void whenClass() throws Exception {
      ApplicationClass applicationClass =
          new ApplicationClass(ApplicationFeatureId.newClass("com.mycompany.Bar"));

      final String str = applicationClass.viewModelMemento();
      final ApplicationFeatureViewModel applicationFeatureVM2 = new ApplicationClass();
      applicationFeatureVM2.viewModelInit(str);

      assertThat(applicationFeatureVM2.getType(), is(ApplicationFeatureType.CLASS));
      assertThat(applicationFeatureVM2.getPackageName(), is("com.mycompany"));
      assertThat(applicationFeatureVM2.getClassName(), is("Bar"));
      assertThat(applicationFeatureVM2.getMemberName(), is(nullValue()));
    }
Example #3
0
 /**
  * Retrieve all application classes with a specific annotation.
  *
  * @param clazz The annotation class.
  * @return A list of application classes.
  */
 public List<ApplicationClass> getAnnotatedClasses(Class<? extends Annotation> clazz) {
   List<ApplicationClass> results = new ArrayList<ApplicationClass>();
   for (ApplicationClass applicationClass : classes.values()) {
     if (!applicationClass.isClass()) {
       continue;
     }
     try {
       Play.classloader.loadClass(applicationClass.name);
     } catch (ClassNotFoundException ex) {
       throw new UnexpectedException(ex);
     }
     if (applicationClass.javaClass.isAnnotationPresent(clazz)) {
       results.add(applicationClass);
     }
   }
   return results;
 }
Example #4
0
 /**
  * Retrieve all application classes assignable to this class.
  *
  * @param clazz The superclass, or the interface.
  * @return A list of application classes.
  */
 public List<ApplicationClass> getAssignableClasses(Class<?> clazz) {
   List<ApplicationClass> results = new ArrayList<ApplicationClass>();
   if (clazz != null) {
     for (ApplicationClass applicationClass : new ArrayList<ApplicationClass>(classes.values())) {
       if (!applicationClass.isClass()) {
         continue;
       }
       try {
         Play.classloader.loadClass(applicationClass.name);
       } catch (ClassNotFoundException ex) {
         throw new UnexpectedException(ex);
       }
       try {
         if (clazz.isAssignableFrom(applicationClass.javaClass)
             && !applicationClass.javaClass.getName().equals(clazz.getName())) {
           results.add(applicationClass);
         }
       } catch (Exception e) {
       }
     }
   }
   return results;
 }