Search in sources :

Example 1 with Parser

use of org.codice.ddf.parser.Parser in project ddf by codice.

the class BasicAuthenticationHandlerTest method testExtractAuthInfo.

@Test
public void testExtractAuthInfo() {
    Parser parser = new XmlParser();
    BasicAuthenticationHandler handler = new BasicAuthenticationHandler();
    UPAuthenticationToken result = (UPAuthenticationToken) handler.extractAuthInfo("Basic " + Base64.getEncoder().encodeToString(CREDENTIALS.getBytes()), "TestRealm");
    assertNotNull(result);
    assertEquals("admin", result.getUsername());
    assertEquals("password", result.getPassword());
    assertEquals("TestRealm", result.getRealm());
    WssBasicAuthenticationHandler wssHandler = new WssBasicAuthenticationHandler(parser);
    BaseAuthenticationToken wssResult = wssHandler.extractAuthInfo("Basic " + Base64.getEncoder().encodeToString(CREDENTIALS.getBytes()), "TestRealm");
    assertNotNull(wssResult);
    assertEquals("", wssResult.getRealm());
    result = (UPAuthenticationToken) handler.extractAuthInfo("Basic " + Base64.getEncoder().encodeToString(":password".getBytes()), "TestRealm");
    assertNotNull(result);
    assertEquals("", result.getUsername());
    assertEquals("password", result.getPassword());
    assertEquals("TestRealm", result.getRealm());
    result = (UPAuthenticationToken) handler.extractAuthInfo("Basic " + Base64.getEncoder().encodeToString("user:".getBytes()), "TestRealm");
    assertNotNull(result);
    assertEquals("user", result.getUsername());
    assertEquals("", result.getPassword());
    assertEquals("TestRealm", result.getRealm());
    result = (UPAuthenticationToken) handler.extractAuthInfo("Basic " + Base64.getEncoder().encodeToString("user/password".getBytes()), "TestRealm");
    assertNull(result);
    result = (UPAuthenticationToken) handler.extractAuthInfo("Basic " + Base64.getEncoder().encodeToString("".getBytes()), "TestRealm");
    assertNull(result);
}
Also used : XmlParser(org.codice.ddf.parser.xml.XmlParser) BaseAuthenticationToken(org.codice.ddf.security.handler.api.BaseAuthenticationToken) UPAuthenticationToken(org.codice.ddf.security.handler.api.UPAuthenticationToken) Parser(org.codice.ddf.parser.Parser) XmlParser(org.codice.ddf.parser.xml.XmlParser) Test(org.junit.Test)

Example 2 with Parser

use of org.codice.ddf.parser.Parser in project ddf by codice.

the class TestXmlMetacardTransformer method setup.

@Before
public void setup() {
    Parser parser = new XmlParser();
    MetacardMarshaller metacardMarshaller = new MetacardMarshallerImpl(parser, new PrintWriterProviderImpl());
    transformer = new XmlMetacardTransformer(metacardMarshaller);
}
Also used : XmlParser(org.codice.ddf.parser.xml.XmlParser) MetacardMarshallerImpl(ddf.catalog.transformer.xml.MetacardMarshallerImpl) MetacardMarshaller(ddf.catalog.transformer.api.MetacardMarshaller) PrintWriterProviderImpl(ddf.catalog.transformer.xml.PrintWriterProviderImpl) XmlMetacardTransformer(ddf.catalog.transformer.xml.XmlMetacardTransformer) XmlParser(org.codice.ddf.parser.xml.XmlParser) Parser(org.codice.ddf.parser.Parser) Before(org.junit.Before)

Example 3 with Parser

use of org.codice.ddf.parser.Parser in project ddf by codice.

the class IntegrationTest method testInputAndOutput.

@Test
public void testInputAndOutput() throws CatalogTransformerException, IOException {
    Parser parser = new XmlParser();
    InputTransformer inputTransformer = new XmlInputTransformer(parser);
    MetacardMarshaller metacardMarshaller = new MetacardMarshallerImpl(parser, new PrintWriterProviderImpl());
    MetacardTransformer outputTransformer = new XmlMetacardTransformer(metacardMarshaller);
    InputStream input = getClass().getResourceAsStream("/extensibleMetacard.xml");
    Metacard metacard = inputTransformer.transform(input);
    LOGGER.info("Attributes: ");
    for (AttributeDescriptor descriptor : metacard.getMetacardType().getAttributeDescriptors()) {
        Attribute attribute = metacard.getAttribute(descriptor.getName());
        LOGGER.info("\t" + descriptor.getName() + ": " + ((attribute == null) ? attribute : attribute.getValue()));
    }
    BinaryContent output = outputTransformer.transform(metacard, mockArguments);
    String outputString = new String(output.getByteArray());
    // TODO test equivalence with XMLUnit.
    LOGGER.info(outputString);
}
Also used : XmlParser(org.codice.ddf.parser.xml.XmlParser) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) XmlMetacardTransformer(ddf.catalog.transformer.xml.XmlMetacardTransformer) Attribute(ddf.catalog.data.Attribute) MetacardMarshaller(ddf.catalog.transformer.api.MetacardMarshaller) InputStream(java.io.InputStream) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) XmlMetacardTransformer(ddf.catalog.transformer.xml.XmlMetacardTransformer) XmlInputTransformer(ddf.catalog.transformer.xml.XmlInputTransformer) InputTransformer(ddf.catalog.transform.InputTransformer) BinaryContent(ddf.catalog.data.BinaryContent) Parser(org.codice.ddf.parser.Parser) XmlParser(org.codice.ddf.parser.xml.XmlParser) MetacardMarshallerImpl(ddf.catalog.transformer.xml.MetacardMarshallerImpl) Metacard(ddf.catalog.data.Metacard) PrintWriterProviderImpl(ddf.catalog.transformer.xml.PrintWriterProviderImpl) XmlInputTransformer(ddf.catalog.transformer.xml.XmlInputTransformer) Test(org.junit.Test)

Example 4 with Parser

use of org.codice.ddf.parser.Parser in project ddf by codice.

the class RegistryTransformerTest method testJaxbElementNullValue.

@Test(expected = CatalogTransformerException.class)
public void testJaxbElementNullValue() throws Exception {
    JAXBElement<RegistryObjectType> mockRegistryObjectType = Mockito.mock(JAXBElement.class);
    when((mockRegistryObjectType).getValue()).thenReturn(null);
    Parser mockParser = Mockito.mock(Parser.class);
    when((mockParser).unmarshal(any(ParserConfigurator.class), any(Class.class), any(InputStream.class))).thenReturn(mockRegistryObjectType);
    registryTransformer.setParser(mockParser);
    convert("/csw-basic-info.xml");
}
Also used : ParserConfigurator(org.codice.ddf.parser.ParserConfigurator) InputStream(java.io.InputStream) RegistryObjectType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryObjectType) XmlParser(org.codice.ddf.parser.xml.XmlParser) Parser(org.codice.ddf.parser.Parser) Test(org.junit.Test)

Example 5 with Parser

use of org.codice.ddf.parser.Parser in project ddf by codice.

the class RegistryTransformerTest method testParserReturnNull.

@Test(expected = CatalogTransformerException.class)
public void testParserReturnNull() throws Exception {
    Parser mockParser = Mockito.mock(Parser.class);
    when((mockParser).unmarshal(any(ParserConfigurator.class), any(Class.class), any(InputStream.class))).thenReturn(null);
    registryTransformer.setParser(mockParser);
    convert("/csw-basic-info.xml");
}
Also used : ParserConfigurator(org.codice.ddf.parser.ParserConfigurator) InputStream(java.io.InputStream) XmlParser(org.codice.ddf.parser.xml.XmlParser) Parser(org.codice.ddf.parser.Parser) Test(org.junit.Test)

Aggregations

Parser (org.codice.ddf.parser.Parser)6 XmlParser (org.codice.ddf.parser.xml.XmlParser)6 Test (org.junit.Test)5 InputStream (java.io.InputStream)4 ParserConfigurator (org.codice.ddf.parser.ParserConfigurator)3 MetacardMarshaller (ddf.catalog.transformer.api.MetacardMarshaller)2 MetacardMarshallerImpl (ddf.catalog.transformer.xml.MetacardMarshallerImpl)2 PrintWriterProviderImpl (ddf.catalog.transformer.xml.PrintWriterProviderImpl)2 XmlMetacardTransformer (ddf.catalog.transformer.xml.XmlMetacardTransformer)2 Attribute (ddf.catalog.data.Attribute)1 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)1 BinaryContent (ddf.catalog.data.BinaryContent)1 Metacard (ddf.catalog.data.Metacard)1 InputTransformer (ddf.catalog.transform.InputTransformer)1 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)1 XmlInputTransformer (ddf.catalog.transformer.xml.XmlInputTransformer)1 RegistryObjectType (oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryObjectType)1 ParserException (org.codice.ddf.parser.ParserException)1 BaseAuthenticationToken (org.codice.ddf.security.handler.api.BaseAuthenticationToken)1 UPAuthenticationToken (org.codice.ddf.security.handler.api.UPAuthenticationToken)1