Package net.vidageek.mirror.dsl

Examples of net.vidageek.mirror.dsl.Mirror


        Annotation annotation;

        // Falls outside the set that assigns a key
        expected = InvalidateSingleCache.class;
        method = "populateAssign01";
        annotation = new Mirror().on(AnnotationDataDummy.class).reflect()
                        .annotation(expected)
                        .atMethod(method).withArgs(String.class);
        AnnotationDataBuilder.populateAssignedKey(data, annotation, expected, method);
        assertEquals("", data.getAssignedKey());

        // Default (or unassigned) value throws an exception
        expected = InvalidateAssignCache.class;
        method = "populateAssign02";
        annotation = new Mirror().on(AnnotationDataDummy.class).reflect()
                        .annotation(expected)
                        .atMethod(method).withArgs(String.class);
        try {
            AnnotationDataBuilder.populateAssignedKey(data, annotation, expected, method);
            fail("expected exception");
        } catch (InvalidParameterException ex) {}
        assertEquals("", data.getAssignedKey());

        // 0-length value throws an exception
        expected = InvalidateAssignCache.class;
        method = "populateAssign03";
        annotation = new Mirror().on(AnnotationDataDummy.class).reflect()
                        .annotation(expected)
                        .atMethod(method).withArgs(String.class);
        try {
            AnnotationDataBuilder.populateAssignedKey(data, annotation, expected, method);
            fail("expected exception");
        } catch (InvalidParameterException ex) {}
        assertEquals("", data.getAssignedKey());

        // Successful assignment
        expected = InvalidateAssignCache.class;
        method = "populateAssign04";
        annotation = new Mirror().on(AnnotationDataDummy.class).reflect()
                        .annotation(expected)
                        .atMethod(method).withArgs(String.class);
        AnnotationDataBuilder.populateAssignedKey(data, annotation, expected, method);
        assertEquals(AnnotationDataDummy.SAMPLE_KEY, data.getAssignedKey());
View Full Code Here


        Annotation annotation;

        // Default Namespace
        expected = InvalidateAssignCache.class;
        method = "populateNamespace01";
        annotation = new Mirror().on(AnnotationDataDummy.class).reflect()
                        .annotation(expected)
                        .atMethod(method).withArgs(String.class);
        try {
            AnnotationDataBuilder.populateNamespace(data, annotation, expected, method);
            fail("expected exception");
        } catch (InvalidParameterException ex) {}
        assertEquals("", data.getNamespace());

        // 0-length String as Namespace
        expected = InvalidateAssignCache.class;
        method = "populateNamespace02";
        annotation = new Mirror().on(AnnotationDataDummy.class).reflect()
                        .annotation(expected)
                        .atMethod(method).withArgs(String.class);
        try {
            AnnotationDataBuilder.populateNamespace(data, annotation, expected, method);
            fail("expected exception");
        } catch (InvalidParameterException ex) {}
        assertEquals("", data.getNamespace());

        // Get the Namespace successfully
        expected = InvalidateAssignCache.class;
        method = "populateNamespace03";
        annotation = new Mirror().on(AnnotationDataDummy.class).reflect()
                        .annotation(expected)
                        .atMethod(method).withArgs(String.class);
        AnnotationDataBuilder.populateNamespace(data, annotation, expected, method);
        assertEquals(AnnotationDataDummy.SAMPLE_NS, data.getNamespace());       
    }
View Full Code Here

        Annotation annotation;

        // Excluded from having an Expiration
        expected = InvalidateAssignCache.class;
        method = "populateExpiration01";
        annotation = new Mirror().on(AnnotationDataDummy.class).reflect()
                        .annotation(expected)
                        .atMethod(method).withArgs(String.class);
        AnnotationDataBuilder.populateExpiration(data, annotation, expected, method);
        assertEquals(0, data.getExpiration());

        // Negative Expiration
        expected = UpdateAssignCache.class;
        method = "populateExpiration02";
        annotation = new Mirror().on(AnnotationDataDummy.class).reflect()
                        .annotation(expected)
                        .atMethod(method).withArgs(String.class);
        try {
            AnnotationDataBuilder.populateExpiration(data, annotation, expected, method);
            fail("expected exception");
        } catch (InvalidParameterException ex) {}
        assertEquals(0, data.getExpiration());

        // Negative Expiration
        expected = UpdateAssignCache.class;
        method = "populateExpiration03";
        annotation = new Mirror().on(AnnotationDataDummy.class).reflect()
                        .annotation(expected)
                        .atMethod(method).withArgs(String.class);
        AnnotationDataBuilder.populateExpiration(data, annotation, expected, method);
        assertEquals(AnnotationDataDummy.SAMPLE_EXP, data.getExpiration());
    }
View Full Code Here

        assertEquals("", data.getClassName());

        // Annotation doesn't match the expected Annotation Class.
        expected = InvalidateAssignCache.class;
        method = "populateClassName01";
        annotation = new Mirror().on(AnnotationDataDummy.class).reflect()
                        .annotation(expected)
                        .atMethod(method).withArgs(String.class);
        try {
            AnnotationDataBuilder.populateClassName(data, annotation, UpdateAssignCache.class);
            fail("expected exception");
        } catch (InvalidParameterException ex) {}
        assertEquals("", data.getClassName());

        // Success
        expected = InvalidateAssignCache.class;
        method = "populateClassName01";
        annotation = new Mirror().on(AnnotationDataDummy.class).reflect()
                        .annotation(expected)
                        .atMethod(method).withArgs(String.class);
        AnnotationDataBuilder.populateClassName(data, annotation, expected);
        assertEquals(expected.getName(), data.getClassName());
    }
View Full Code Here

        assertEquals("", data.getKeyProviderBeanName());
        assertEquals(AnnotationData.DEFAULT_INTEGER, data.getKeyIndex());

        // No KeyProvider annotations at all
        expected = InvalidateSingleCache.class;
        targetMethod = new Mirror().on(AnnotationDataDummy.class).reflect()
                .method("populateKeyProvider01").withArgs(String.class);
        try {
            AnnotationDataBuilder.populateKeyIndexAndBeanName(data, expected, targetMethod);
            fail("expected exception");
        } catch (InvalidParameterException ex) {}
        assertEquals("", data.getKeyProviderBeanName());
        assertEquals(AnnotationData.DEFAULT_INTEGER, data.getKeyIndex());

        // ReturnKeyProvider with an empty bean name
        expected = InvalidateSingleCache.class;
        targetMethod = new Mirror().on(AnnotationDataDummy.class).reflect()
                .method("populateKeyProvider02").withArgs(String.class);
        try {
            AnnotationDataBuilder.populateKeyIndexAndBeanName(data, expected, targetMethod);
            fail("expected exception");
        } catch (InvalidParameterException ex) {}
        assertEquals("", data.getKeyProviderBeanName());
        assertEquals(AnnotationData.DEFAULT_INTEGER, data.getKeyIndex());

        // ParamKeyProvider with an empty bean name
        expected = InvalidateSingleCache.class;
        targetMethod = new Mirror().on(AnnotationDataDummy.class).reflect()
                .method("populateKeyProvider03").withArgs(String.class);
        try {
            AnnotationDataBuilder.populateKeyIndexAndBeanName(data, expected, targetMethod);
            fail("expected exception");
        } catch (InvalidParameterException ex) {}
        assertEquals("", data.getKeyProviderBeanName());
        assertEquals(AnnotationData.DEFAULT_INTEGER, data.getKeyIndex());

        // Multiple ParamKeyProviders
        expected = InvalidateSingleCache.class;
        targetMethod = new Mirror().on(AnnotationDataDummy.class).reflect()
                .method("populateKeyProvider04").withArgs(String.class, String.class);
        try {
            AnnotationDataBuilder.populateKeyIndexAndBeanName(data, expected, targetMethod);
            fail("expected exception");
        } catch (InvalidParameterException ex) {}
        assertEquals("", data.getKeyProviderBeanName());
        assertEquals(AnnotationData.DEFAULT_INTEGER, data.getKeyIndex());

        // Param KeyProvider with override
        expected = InvalidateSingleCache.class;
        targetMethod = new Mirror().on(AnnotationDataDummy.class).reflect()
                .method("populateKeyProvider05").withArgs(String.class, String.class, String.class);
        AnnotationDataBuilder.populateKeyIndexAndBeanName(data, expected, targetMethod);
        assertEquals(AnnotationDataDummy.SAMPLE_PARAM_BEAN, data.getKeyProviderBeanName());
        assertEquals(2, data.getKeyIndex());

        // Return KeyProvider with override
        expected = InvalidateSingleCache.class;
        targetMethod = new Mirror().on(AnnotationDataDummy.class).reflect()
                .method("populateKeyProvider06").withArgs(String.class);
        AnnotationDataBuilder.populateKeyIndexAndBeanName(data, expected, targetMethod);
        assertEquals(AnnotationDataDummy.SAMPLE_RETURN_BEAN, data.getKeyProviderBeanName());
        assertEquals(-1, data.getKeyIndex());

        // Param KeyProvider without override
        expected = InvalidateSingleCache.class;
        targetMethod = new Mirror().on(AnnotationDataDummy.class).reflect()
                .method("populateKeyProvider07").withArgs(String.class, String.class, String.class);
        AnnotationDataBuilder.populateKeyIndexAndBeanName(data, expected, targetMethod);
        assertEquals(AnnotationConstants.DEFAULT_KEY_PROVIDER_BEAN_NAME, data.getKeyProviderBeanName());
        assertEquals(1, data.getKeyIndex());

        // Return KeyProvider without override
        expected = InvalidateSingleCache.class;
        targetMethod = new Mirror().on(AnnotationDataDummy.class).reflect()
                .method("populateKeyProvider08").withArgs(String.class);
        AnnotationDataBuilder.populateKeyIndexAndBeanName(data, expected, targetMethod);
        assertEquals(AnnotationConstants.DEFAULT_KEY_PROVIDER_BEAN_NAME, data.getKeyProviderBeanName());
        assertEquals(-1, data.getKeyIndex());
    }
View Full Code Here

        AnnotationDataBuilder.populateDataIndexFromAnnotations(data, expected, null);
        assertEquals(AnnotationData.DEFAULT_INTEGER, data.getDataIndex());

        // Not an update type.
        expected = UpdateAssignCache.class;
        targetMethod = new Mirror().on(AnnotationDataDummy.class).reflect()
                .method("populateData01").withArgs(String.class);
        try {
            AnnotationDataBuilder.populateDataIndexFromAnnotations(data, expected, targetMethod);
            fail("expected exception");
        } catch (InvalidParameterException ex) {}
        assertEquals(AnnotationData.DEFAULT_INTEGER, data.getDataIndex());

        // Multiple Parameter data values
        expected = UpdateAssignCache.class;
        targetMethod = new Mirror().on(AnnotationDataDummy.class).reflect()
                .method("populateData02").withArgs(String.class, String.class);
        try {
            AnnotationDataBuilder.populateDataIndexFromAnnotations(data, expected, targetMethod);
            fail("expected exception");
        } catch (InvalidParameterException ex) {}
        assertEquals(AnnotationData.DEFAULT_INTEGER, data.getDataIndex());

        // Return data values
        expected = UpdateAssignCache.class;
        targetMethod = new Mirror().on(AnnotationDataDummy.class).reflect()
                .method("populateData03").withArgs(String.class);
        AnnotationDataBuilder.populateDataIndexFromAnnotations(data, expected, targetMethod);
        assertEquals(-1, data.getDataIndex());

        // Parameter data values
        expected = UpdateAssignCache.class;
        targetMethod = new Mirror().on(AnnotationDataDummy.class).reflect()
                .method("populateData04").withArgs(String.class, String.class);
        AnnotationDataBuilder.populateDataIndexFromAnnotations(data, expected, targetMethod);
        assertEquals(1, data.getDataIndex());

    }
View Full Code Here

  }

  private List<Method> getMethods(Class<?> controller) {
    List<Method> methods = new ArrayList<>();
   
    for (Method method : new Mirror().on(controller).reflectAll().methods()) {
      if (!method.getDeclaringClass().equals(Object.class)) {
        methods.add(method);
      }
    }
   
View Full Code Here

    public String getLink() {
      Method method = null;

      if (countMethodsWithSameName() > 1) {
        method = new Mirror().on(controller).reflect().method(methodName).withArgs(getClasses(args));
        if (method == null && args.isEmpty()) {
          throw new IllegalArgumentException("Ambiguous method '" + methodName + "' on " + controller + ". Try to add some parameters to resolve ambiguity, or use different method names.");
        }
      } else {
        method = findMethodWithName(controller, methodName);
View Full Code Here

    } else {
      types.add(getRootClass());
    }
   
    for (Class<?> type : types) {
      for (Field field : new Mirror().on(type).reflectAll().fields()) {
        getExcludes().putAll(field.getName(), getParentTypes(field.getName(), type));
      }
    } 
  }
View Full Code Here

    }
    return types;
  }
 
  private Field reflectField(String path, Class<?> type) {
    Field field = new Mirror().on(type).reflect().field(path.replaceAll("\\?", ""));
    if (!path.startsWith("?"))
      checkNotNull(field);
    return field;
  }
View Full Code Here

TOP

Related Classes of net.vidageek.mirror.dsl.Mirror

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.