@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_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)); 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 = 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); }
@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 = CFG304, desc = "Bean does not exist.") public static AbortRuntimeException CFG304_BEAN_DOESNT_EXIST(BeanId id) { Event event = new Event(MODULE_NAME, CFG304, MessageFormat.format(CFG304_MSG, id)); 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 = CFG306, desc = "Property is not mutable.") public static AbortRuntimeException CFG306_PROPERTY_IMMUTABLE(BeanId id, String propertyName) { Event event = new Event(MODULE_NAME, CFG306, MessageFormat.format(CFG306_MSG, id, propertyName)); return new AbortRuntimeException(event); }
@Override public void registerDefault(Object... instances) { doLookup(); for (Object instance : instances) { Bean bean = conversion.convert(instance, Bean.class); 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 = CFG307, desc = "Singleton beans cannot be removed.") public static AbortRuntimeException CFG307_SINGELTON_REMOVAL(BeanId id) { Event event = new Event(MODULE_NAME, CFG307, MessageFormat.format(CFG307_MSG, id)); return new AbortRuntimeException(event); }
@Test public void test_remove_schema() { Set<Schema> schemas = generateSchemas(2, 2); for (Schema schema : schemas) { manager.registerSchema(schema); Schema response = manager.getSchema(schema.getName()); assertThat(schema, equalTo(response)); } Schema s = schemas.iterator().next(); assertThat(manager.getSchema(s.getName()), is(s)); manager.removeSchema(s.getName()); try { s = manager.getSchema(s.getName()); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(Events.CFG101)); } }
@EventDoc(module = MODULE_NAME, code = CFG309, desc = "Bean application validation failed.") public static AbortRuntimeException CFG309_VALIDATION_ERROR(String msg) { Event event = new Event(MODULE_NAME, CFG309, MessageFormat.format(CFG309_MSG, msg)); 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)); assertThat(observer.getChanges().size(), is(0)); fail("Not possible to set property names that does not exist in schema"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG110)); assertThat(observer.getChanges().size(), is(0)); fail("Not possible to set property names that does not exist in schema"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG110)); assertThat(observer.getChanges().size(), is(0)); fail("Not possible to set property names that does not exist in schema"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG111)); assertThat(observer.getChanges().size(), is(0)); fail("Not possible to set property names that does not exist in schema"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG110)); assertThat(observer.getChanges().size(), is(0)); fail("Not possible to set property names that does not exist in schema"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG110)); assertThat(observer.getChanges().size(), is(0));
@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); }
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 = CFG311, desc = "Default beans cannot be removed.") public static AbortRuntimeException CFG311_DEFAULT_REMOVAL(BeanId id) { Event event = new Event(MODULE_NAME, CFG311, MessageFormat.format(CFG311_MSG, id)); 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 = CFG106, desc = "Bean have a property value of invalid multiplicity type according to schema.") public static AbortRuntimeException CFG106_WRONG_MULTIPLICITY_TYPE(BeanId id, String propertyName) { Event event = new Event(MODULE_NAME, CFG106, MessageFormat.format(CFG106_MSG, id, propertyName)); return new AbortRuntimeException(event); }
fail("Should not be possible to merge invalid reference"); } catch (AbortRuntimeException e) { if (e.getEvent().getCode() != CFG301 && e.getEvent().getCode() != CFG304) { fail("Should not be possible to merge invalid reference"); assertThat(observer.getChanges().size(), is(0)); } catch (AbortRuntimeException e) { if (e.getEvent().getCode() != CFG301 && e.getEvent().getCode() != CFG304) { fail("Should not be possible to merge invalid reference"); fail("Should not be possible to merge beans that does not exist"); } catch (AbortRuntimeException e) { if (e.getEvent().getCode() != CFG301 && e.getEvent().getCode() != CFG304) { fail("Should not be possible to merge invalid reference"); fail("Should not be possible to merge invalid reference"); } catch (AbortRuntimeException e) { if (e.getEvent().getCode() != CFG301 && e.getEvent().getCode() != CFG304) { fail("Should not be possible to merge invalid reference");
@EventDoc(module = MODULE_NAME, code = CFG107, desc = CFG107_MSG) public static AbortRuntimeException CFG107_MISSING_ID() { Event event = new Event(MODULE_NAME, CFG106, CFG107_MSG); return new AbortRuntimeException(event); }