public EntityParser(Class<?> table) { if (!table.isAnnotationPresent(Entity.class) || !table.isAnnotationPresent(javax.persistence.Table.class)) { throw new AnnotationFormatError("The class hasn't got Entity or Table annotation!"); } entity = table; }
@Test public void throwsExceptionWhenParameterHasNoAnnotations() throws Exception { Method method = this.getClass().getMethod("parameterWithNoAnnotations", String.class); try { singleParameterSupplier.getValueForParameter(method, method.getParameterTypes()[0], method.getParameterAnnotations()[0]); fail("Expected exception"); } catch (AnnotationFormatError e) { assertThat(e.getMessage(), containsString("parameters annotated with '" + ExampleName.class.getName())); } }
@Test public void throwsExceptionWhenParameterHasMultipleAnnotations() throws Exception { Method method = this.getClass().getMethod("parameterWithMultipleAnnotations", String.class); try { singleParameterSupplier.getValueForParameter(method, method.getParameterTypes()[0], method.getParameterAnnotations()[0]); fail("Expected exception"); } catch (AnnotationFormatError e) { assertThat(e.getMessage(), containsString("parameters annotated with '" + ExampleName.class.getName())); } }
@Override public void loadValueIntoField(Object fixtureObject) { field.setAccessible(true); try { Object value = scopedObject.getObject(); field.set(fixtureObject, value); } catch (InstantiationException e) { throw new AnnotationFormatError("Could not create object on field " + field.getName()); } catch (IllegalAccessException e) { throw new AnnotationFormatError("Could not set object on field " + field.getName()); } }
@Test public void throwsExceptionWhenParameterTypeIsIncorrect() throws Exception { Method method = this.getClass().getMethod("incorrectParamType", int.class); try { singleParameterSupplier.getValueForParameter(method, method.getParameterTypes()[0], method.getParameterAnnotations()[0]); fail("Expected exception"); } catch (AnnotationFormatError e) { assertThat(e.getMessage(), containsString("is expected to be of type 'java.lang.String'")); } }
@Override public void loadValueIntoField(Object fixtureObject) { field.setAccessible(true); try { Object value = scopedObject.getObject(); field.set(fixtureObject, value); } catch (InstantiationException e) { throw new AnnotationFormatError("Could not create object on field " + field.getName()); } catch (IllegalAccessException e) { throw new AnnotationFormatError("Could not set object on field " + field.getName()); } }
@Test public void before() { try { new FixtureInstance(this); fail("Expected AnnotationFormatError since only types of ScopedObjectHolder can be annotated with ConcordionScoped"); } catch (AnnotationFormatError e) { assertThat(e.getMessage(), containsString("The 'ConcordionScoped' annotation can only be applied to fields of type 'ScopedObjectHolder'")); } } }
@Override public Object getValueForParameter(Method method, Class<?> parameterClass, Annotation[] annotations) { if (annotations.length != 1) { throw new AnnotationFormatError("Error invoking " + method.getName() + ". Methods annotated with '" + methodAnnotationClass.getName() + "' can only have parameters annotated with '" + parameterAnnotation.getName() + "'."); } Annotation annotation = annotations[0]; if (parameterAnnotation.equals(annotation.annotationType())) { if (!(parameterClass.equals(parameterValue.getClass()))) { throw new AnnotationFormatError("Error invoking '" + method + "'. Parameter with annotation '" + parameterAnnotation + "' is expected to be of type '" + parameterValue.getClass().getName() + "'"); } return parameterValue; } throw new AnnotationFormatError("Error invoking " + method.getName() + ". Methods annotated with '" + methodAnnotationClass.getName() + "' can only have parameters annotated with '" + parameterAnnotation.getName() + "'."); } }
@Override public Object getValueForParameter(Method method, Class<?> parameterClass, Annotation[] annotations) { if (annotations.length != 1) { throw new AnnotationFormatError("Error invoking " + method.getName() + ". Methods annotated with '" + methodAnnotationClass.getName() + "' can only have parameters annotated with '" + parameterAnnotation.getName() + "'."); } Annotation annotation = annotations[0]; if (parameterAnnotation.equals(annotation.annotationType())) { if (!(parameterClass.equals(parameterValue.getClass()))) { throw new AnnotationFormatError("Error invoking '" + method + "'. Parameter with annotation '" + parameterAnnotation + "' is expected to be of type '" + parameterValue.getClass().getName() + "'"); } return parameterValue; } throw new AnnotationFormatError("Error invoking " + method.getName() + ". Methods annotated with '" + methodAnnotationClass.getName() + "' can only have parameters annotated with '" + parameterAnnotation.getName() + "'."); } }
@Override public void saveValueFromField(Object fixtureObject) { field.setAccessible(true); Object currentValue = null; try { currentValue = field.get(fixtureObject); } catch (IllegalAccessException e) { throw new AnnotationFormatError("Could not get object on field " + field.getName()); } scopedObject.setObject(currentValue); }
/** * Retrieves the input record structure from the {@link uk.gov.gchq.gaffer.function.annotation.Inputs} annotation. */ private void processOutputAnnotation() { final Outputs annotation = getClass().getAnnotation(Outputs.class); if (null == annotation) { throw new AnnotationFormatError("All consumer producer function classes must have outputs defined using the 'Outputs' annotation on the class." + " Class: " + getClass()); } outputs = annotation.value(); }
@Override public void saveValueFromField(Object fixtureObject) { field.setAccessible(true); Object currentValue = null; try { currentValue = field.get(fixtureObject); } catch (IllegalAccessException e) { throw new AnnotationFormatError("Could not get object on field " + field.getName()); } scopedObject.setObject(currentValue); }
/** * Retrieves the input record structure from the {@link uk.gov.gchq.gaffer.function.annotation.Inputs} annotation. */ private void processInputAnnotation() { final Inputs annotation = getClass().getAnnotation(Inputs.class); if (null == annotation) { throw new AnnotationFormatError("All consumer function classes must have inputs defined using the 'Inputs' annotation on the class." + " Class: " + getClass()); } inputs = annotation.value(); }
/** * Retrieves the input record structure from the {@link uk.gov.gchq.gaffer.function.annotation.Inputs} annotation. */ private void processOutputAnnotation() { final Outputs annotation = getClass().getAnnotation(Outputs.class); if (null == annotation || null == annotation.value()) { throw new AnnotationFormatError("All producer function classes must have outputs defined using the 'Outputs' annotation on the class."); } outputs = annotation.value(); }
private void createScopedObjectField(FixtureType fixtureType, Field field) { if (!field.getType().equals(ScopedObjectHolder.class)) { throw new AnnotationFormatError(SimpleFormatter.format("The '%s' annotation can only be applied to fields of type '%s'", ConcordionScoped.class.getSimpleName(), ScopedObjectHolder.class.getSimpleName())); } ConcordionScoped annotation = field.getAnnotation(ConcordionScoped.class); Scope fieldScope = annotation.value(); String name = field.getName(); ScopedObject scopedObject = createScopedObject(fixtureType, name, fieldScope); scopedFields.get(fieldScope).add(new ScopedFieldImpl(scopedObject, field)); }
private void createScopedObjectField(FixtureType fixtureType, Field field) { if (!field.getType().equals(ScopedObjectHolder.class)) { throw new AnnotationFormatError(SimpleFormatter.format("The '%s' annotation can only be applied to fields of type '%s'", ConcordionScoped.class.getSimpleName(), ScopedObjectHolder.class.getSimpleName())); } ConcordionScoped annotation = field.getAnnotation(ConcordionScoped.class); Scope fieldScope = annotation.value(); String name = field.getName(); ScopedObject scopedObject = createScopedObject(fixtureType, name, fieldScope); scopedFields.get(fieldScope).add(new ScopedFieldImpl(scopedObject, field)); }
if (parameters.length > 0) { if (parameterSupplier == null) { throw new AnnotationFormatError("Error invoking " + method + ". Methods annotated with '" + methodAnnotation + "' are not allowed parameters"); throw new AnnotationFormatError("Invalid permissions to invoke method: " + method.getName()); } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) {
if (parameters.length > 0) { if (parameterSupplier == null) { throw new AnnotationFormatError("Error invoking " + method + ". Methods annotated with '" + methodAnnotation + "' are not allowed parameters"); throw new AnnotationFormatError("Invalid permissions to invoke method: " + method.getName()); } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) {
throw new AnnotationFormatError("cacheName must be specified in either CacheDefaults or CacheRemove or CacheRemoveAll for: " + method);
} else if (CacheValue.class.isAssignableFrom(parameterAnnotation.annotationType())) { if (!cacheValueAllowed) { throw new AnnotationFormatError("CacheValue parameter annotation is not allowed on " + method); } else if (cacheValueParameter != null || isValue) { throw new AnnotationFormatError("Multiple CacheValue parameter annotations are not allowed: " + method); } else { isValue = true;