SimpleNamespaceContext { public static NamespaceContext create(KeyValuePairSet set) { if (set == null || set.size() == 0) { return null; } return new NamespaceContextMap(set); }  static NamespaceContext create(KeyValuePairSet set); static NamespaceContext create(KeyValuePairSet set, AdaptrisMessage msg);  }
@Test public void testCreateKeyValuePairSet() { assertNull(SimpleNamespaceContext.create(null)); assertNull(SimpleNamespaceContext.create(new KeyValuePairSet())); assertNotNull(SimpleNamespaceContext.create(createNamespaceEntries())); assertNotNull(SimpleNamespaceContext.create(createWithDefaultEntries())); }
@Test(expected = IllegalArgumentException.class) public void testInvalidNamespace() throws Exception { SimpleNamespaceContext.create(createBrokenEntries()); }
@Test public void testCreateKeyValuePairSetAdaptrisMessage() { AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); assertNull(SimpleNamespaceContext.create(null, msg)); assertNull(SimpleNamespaceContext.create(new KeyValuePairSet(), msg)); NamespaceContext ctx = SimpleNamespaceContext.create(createNamespaceEntries()); msg.addObjectHeader(SimpleNamespaceContext.class.getCanonicalName(), ctx); NamespaceContext ctx2 = SimpleNamespaceContext.create(null, msg); assertEquals(ctx, ctx2); NamespaceContext ctx3 = SimpleNamespaceContext.create(createNamespaceEntries(), msg); assertNotSame(ctx, ctx3); }
@Test public void testNamespaceURI() throws Exception { NamespaceContext ctx = SimpleNamespaceContext.create(createNamespaceEntries()); assertEquals(XMLConstants.NULL_NS_URI, ctx.getNamespaceURI(null)); assertEquals(XMLConstants.NULL_NS_URI, ctx.getNamespaceURI("blahblah")); assertEquals("http: }
@Test public void testGetPrefix() throws Exception { NamespaceContext ctx = SimpleNamespaceContext.create(createNamespaceEntries()); assertNull(ctx.getPrefix(null)); assertNull(ctx.getPrefix("http: assertEquals("xsd", ctx.getPrefix("http: }
@Test public void testGetPrefixes() throws Exception { NamespaceContext ctx = SimpleNamespaceContext.create(createNamespaceEntries()); assertNull(ctx.getPrefixes(null)); assertNotNull(ctx.getPrefixes("http: assertNull(ctx.getPrefixes("http: }