@EventDoc(module = MODULE_NAME, code = CFG102, desc = "Class is not configurable.") public static AbortRuntimeException CFG102_NOT_CONFIGURABLE(Class<?> clazz) { Event event = new Event(MODULE_NAME, CFG102, MessageFormat.format(CFG102_MSG, clazz.getName())); return new AbortRuntimeException(event); }
public Response toResponse(Exception ex) { if (ex instanceof AbortRuntimeException) { AbortRuntimeException abort = (AbortRuntimeException) ex; log.warn("{}", ex.getMessage()); log.debug("Exception occured.", ex); Event e = abort.getEvent(); Status status = getStatus(e); return Response.serverError().status(status).entity(e.getMessage()).build(); } else if (ex instanceof WebApplicationException) { WebApplicationException webex = (WebApplicationException) ex; return Response.serverError().status(webex.getResponse().getStatus()).build(); } else { log.warn("Unexpected INTERNAL_SERVER_ERROR ", ex); return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build(); } }
@Test public void test_delete_reference_violation() { admin.createObjects(Arrays.asList(g1, g2, p1, p2, c1, c2)); // test single try { admin.delete(BeanId.create("c1", ConfigTestData.CHILD_SCHEMA_NAME)); fail("Should not be possible to delete a bean with references"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG302)); } // test multiple try { admin.delete(ConfigTestData.CHILD_SCHEMA_NAME, Arrays.asList("c1", "c2")); fail("Should not be possible to delete a bean with references"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG302)); } }
@Test public void test_set_merge_without_schema() { Bean b = Bean.create(BeanId.create("1", "missing_schema_name")); try { admin.create(b); fail("Cant add beans without a schema."); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG101)); } try { admin.merge(b); fail("Cant add beans without a schema."); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG101)); } }
@EventDoc(module = MODULE_NAME, code = CFG104, desc = "Configurable class have a property of unsupported type.") public static AbortRuntimeException CFG104_UNSUPPORTED_PROPERTY(Class<?> clazz, String property, Class<?> type) { Event event = new Event(MODULE_NAME, CFG104, MessageFormat.format(CFG104_MSG, clazz.getName(), property, type.getName())); return new AbortRuntimeException(event); }
@Test public void test_set_merge_without_schema() { Bean b = Bean.create(BeanId.create("1", "missing_schema_name")); try { admin.create(b); fail("Cant add beans without a schema."); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG101)); assertThat(observer.getChanges().size(), is(0)); } try { admin.merge(b); fail("Cant add beans without a schema."); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG101)); assertThat(observer.getChanges().size(), is(0)); } }
@EventDoc(module = MODULE_NAME, code = CFG109, desc = "Bean property have illegal map parameterization.") public static AbortRuntimeException CFG109_ILLEGAL_MAP(String propertyName) { Event event = new Event(MODULE_NAME, CFG109, MessageFormat.format(CFG109_MSG, propertyName)); return new AbortRuntimeException(event); }
@Override public void registerDefault(Object... instances) { doLookup(); for (Object instance : instances) { Bean bean = schemaManager.convertObject(instance); bean.setDefault(); try { beanManager.create(bean); } catch (AbortRuntimeException e) { // ignore if bean already exist if (e.getEvent().getCode() != CFG303) { throw e; } } } }
@EventDoc(module = MODULE_NAME, code = CFG111, desc = "Bean have reference that does not exist in schema.") public static AbortRuntimeException CFG111_REF_NOT_EXIST_IN_SCHEMA(String referenceName) { Event event = new Event(MODULE_NAME, CFG111, MessageFormat.format(CFG111_MSG, referenceName)); return new AbortRuntimeException(event); }
@Produces public ServerSpecificConfigProxy<T> produceServerConfigProxy(InjectionPoint ip){ Class<?> declaringClass = ip.getMember().getDeclaringClass(); Class<?> configCls = getParameterizedType(declaringClass, ip.getAnnotated().getBaseType()); try { Optional<?> optionalServer = config.get(serverName.getName(), configCls); if (optionalServer.isPresent()) { return new ServerSpecificConfigProxy(optionalServer.get()); } else { log.debug("Config instance {} of type {} not found", serverName.getName(), configCls); Object config = newInstance(configCls, serverName.getName()); return new ServerSpecificConfigProxy(config); } } catch (AbortRuntimeException e) { if (e.getEvent().getCode() != Events.CFG304){ throw e; } log.debug("Config instance {} of type {} not found", serverName.getName(), configCls); Object config = newInstance(configCls, serverName.getName()); return new ServerSpecificConfigProxy(config); } }
@EventDoc(module = MODULE_NAME, code = CFG102, desc = "Class is not configurable.") public static AbortRuntimeException CFG102_NOT_CONFIGURABLE(Class<?> clazz) { Event event = new Event(MODULE_NAME, CFG102, MessageFormat.format(CFG102_MSG, clazz.getName())); return new AbortRuntimeException(event); }
@Test public void test_delete_reference_violation() { admin.create(toBeans(g1, g2, p1, p2, c1, c2)); observer.clear(); // test single try { admin.delete(BeanId.create("c1", CHILD_SCHEMA_NAME)); fail("Should not be possible to delete a bean with references"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG302)); assertThat(observer.getChanges().size(), is(0)); } // test multiple try { admin.delete(CHILD_SCHEMA_NAME, Arrays.asList("c1", "c2")); fail("Should not be possible to delete a bean with references"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG302)); assertThat(observer.getChanges().size(), is(0)); } }
@EventDoc(module = MODULE_NAME, code = CFG110, desc = "Bean have property that does not exist in schema.") public static AbortRuntimeException CFG110_PROP_NOT_EXIST_IN_SCHEMA(String propertyName) { Event event = new Event(MODULE_NAME, CFG110, MessageFormat.format(CFG110_MSG, propertyName)); return new AbortRuntimeException(event); }
@Test public void test_delete_default() { List<Bean> beans = generateBeans(2, 2); for (Bean bean : beans) { bean.setDefault(); } manager.create(beans); for (Bean bean : beans) { try { manager.delete(bean.getId()); fail("Should not be able to delete default instances"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG311)); } } } }
@EventDoc( module = MODULE_NAME, code = CFG302, desc = "One or more beans cannot be deleted beacuse of existing references from other beans. ") public static AbortRuntimeException CFG302_CANNOT_DELETE_BEAN(Collection<BeanId> id) { Event event = new Event(MODULE_NAME, CFG302, MessageFormat.format(CFG302_MSG, id)); return new AbortRuntimeException(event); }
fail("Not possible to set property names that does not exist in schema"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG110)); fail("Not possible to set property names that does not exist in schema"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG110)); fail("Not possible to set property names that does not exist in schema"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG110)); fail("Not possible to set property names that does not exist in schema"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG111)); fail("Not possible to set property names that does not exist in schema"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG110)); fail("Not possible to set property names that does not exist in schema"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG110));
@EventDoc(module = MODULE_NAME, code = CFG101, desc = "Config schema does not exist.") public static AbortRuntimeException CFG101_SCHEMA_NOT_EXIST(String schemaName) { Event event = new Event(MODULE_NAME, CFG101, MessageFormat.format(CFG101_MSG, schemaName)); return new AbortRuntimeException(event); }
@EventDoc(module = MODULE_NAME, code = CFG301, desc = "Bean have a missing references.") public static AbortRuntimeException CFG301_MISSING_RUNTIME_REF(BeanId id, BeanId ref) { Event event = new Event(MODULE_NAME, CFG301, MessageFormat.format(CFG301_MSG_1, id, ref)); return new AbortRuntimeException(event); }