public static Status getStatus(Event e) { Status status; switch (e.getCode()) { case Events.CFG101: status = Status.NOT_FOUND;
@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)); } }
@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; } } } }
@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)); } }
@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); } }
@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)); } }
@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)); } } } }
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));
fail("10000 does not fit java.lang.Byte"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG105)); fail("2.2 does not fit a collection of java.lang.Integer"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG105)); fail("not_a_enum is not a value of TimeUnit"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG105)); fail("not_a_enum is not a value of TimeUnit"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG105)); fail("Cannot add mutiple values to a single valued property."); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG106)); fail("Cannot add a value to a single typed value."); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG105));
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");
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));
fail("Area exceeds constraint"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG309)); fail("Prop does not have first upper case."); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG309)); fail("Prop must be longer than one char"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG309)); fail("Width and height may not be null."); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG309));
fail("Area exceeds constraint"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG309)); fail("Prop does not have first upper case."); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG309)); fail("Prop must be longer than one char"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG309)); fail("Width and height may not be null."); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG309));
fail("10000 does not fit java.lang.Byte"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG105)); assertThat(observer.getChanges().size(), is(0)); fail("2.2 does not fit a collection of java.lang.Integer"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG105)); assertThat(observer.getChanges().size(), is(0)); fail("not_a_enum is not a value of TimeUnit"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG105)); assertThat(observer.getChanges().size(), is(0)); fail("not_a_enum is not a value of TimeUnit"); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG105)); assertThat(observer.getChanges().size(), is(0)); fail("Cannot add mutiple values to a single valued property."); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG106)); assertThat(observer.getChanges().size(), is(0)); fail("Cannot add a value to a single typed value."); } catch (AbortRuntimeException e) { assertThat(e.getEvent().getCode(), is(CFG105)); assertThat(observer.getChanges().size(), is(0));
assertThat(e.getEvent().getCode(), is(CFG309));
assertThat(e.getEvent().getCode(), is(CFG309));
fail("Should not be possible to merge invalid reference"); } catch (AbortRuntimeException e) { if (e.getEvent().getCode() != CFG301) { 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) { 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) { 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) { fail("Should not be possible to merge invalid reference");