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);
}
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);
}
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);
}
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");
}
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");
}
Aggregations