/** Verify registered components are serialized in alphabetical order */ public void testSerializeAsPart() throws Exception { InstanceStack iStack = new InstanceStack(); iStack.setConfigAdapter(mci); JsonEncoder jsonMock = Mockito.mock(JsonEncoder.class); BaseComponent<?, ?> a = getComponentWithPath("a"); BaseComponent<?, ?> b = getComponentWithPath("b"); BaseComponent<?, ?> c = getComponentWithPath("c"); iStack.registerComponent(b); iStack.registerComponent(c); iStack.registerComponent(a); iStack.serializeAsPart(jsonMock); List<BaseComponent<?, ?>> sorted = Lists.newArrayList(); sorted.add(a); sorted.add(b); sorted.add(c); verify(jsonMock).writeMapKey("components"); verify(jsonMock).writeArray(sorted); }
public void testComponents() { InstanceStack iStack = new InstanceStack(); iStack.setConfigAdapter(mci); Map<String, BaseComponent<?, ?>> comps = iStack.getComponents(); assertNotNull("Components should never be null", comps); assertEquals("Components should empty", 0, comps.size()); BaseComponent<?, ?> x = getComponentWithPath("a"); iStack.registerComponent(x); comps = iStack.getComponents(); assertNotNull("Components should never be null", comps); assertEquals("Components should have one component", 1, comps.size()); assertEquals("Components should have x", x, comps.get("a")); BaseComponent<?, ?> y = getComponentWithPath("b"); iStack.registerComponent(y); comps = iStack.getComponents(); assertNotNull("Components should never be null", comps); assertEquals("Components should have two components", 2, comps.size()); assertEquals("Components should have x", x, comps.get("a")); assertEquals("Components should have y", y, comps.get("b")); }
@Override public void registerComponent(BaseComponent<?, ?> component) { InstanceStack iStack = getInstanceStack(); if (iStack.isUnprivileged()) { if (componentCount++ > MAX_COMPONENT_COUNT) { // // This is bad, try to give the poor user an idea of what happened. // Action tmp = getCurrentAction(); StringBuffer sb = new StringBuffer(); if (tmp != null) { sb.append(tmp); sb.append("("); tmp.logParams(new SBKeyValueLogger(sb)); sb.append(")"); } else { sb.append("request"); } throw new SystemErrorException("Too many components for " + sb.toString()); } } iStack.registerComponent(component); }