use of javax.ws.rs.core.UriInfo in project ddf by codice.
the class TestRestEndpoint method createSpecificUriInfo.
/**
* Creates a UriInfo with a user specified URL
*
* @param url
* @return
* @throws URISyntaxException
*/
protected UriInfo createSpecificUriInfo(String url) throws URISyntaxException {
UriInfo uriInfo = mock(UriInfo.class);
URI uri = new URI(url);
when(uriInfo.getAbsolutePath()).thenReturn(uri);
when(uriInfo.getQueryParameters()).thenReturn(mock(MultivaluedMap.class));
return uriInfo;
}
use of javax.ws.rs.core.UriInfo in project ddf by codice.
the class TestRestEndpoint method executeTest.
private Response executeTest(CatalogFramework framework, String transformer, boolean local, HttpServletRequest request) throws URISyntaxException {
RESTEndpoint restEndpoint = new RESTEndpoint(framework);
restEndpoint.setTikaMimeTypeResolver(new TikaMimeTypeResolver());
FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
restEndpoint.setFilterBuilder(filterBuilder);
UriInfo uriInfo;
Response response;
if (local) {
uriInfo = createSpecificUriInfo(LOCAL_RETRIEVE_ADDRESS);
response = restEndpoint.getDocument(GET_ID, transformer, uriInfo, request);
} else {
uriInfo = createSpecificUriInfo(FED_RETRIEVE_ADDRESS);
response = restEndpoint.getDocument(GET_SITENAME, GET_ID, transformer, uriInfo, request);
}
return response;
}
use of javax.ws.rs.core.UriInfo in project ddf by codice.
the class TestRestEndpoint method headTest.
private Response headTest(boolean local) throws CatalogTransformerException, URISyntaxException, UnsupportedEncodingException, UnsupportedQueryException, SourceUnavailableException, FederationException, IngestException {
MetacardImpl metacard = null;
List<Result> list = new ArrayList<Result>();
Result result = mock(Result.class);
InputStream inputStream = null;
UriInfo uriInfo;
Response response;
CatalogFramework framework = givenCatalogFramework(SAMPLE_ID);
list.add(result);
QueryResponse queryResponse = mock(QueryResponse.class);
when(queryResponse.getResults()).thenReturn(list);
when(framework.query(isA(QueryRequest.class), isNull(FederationStrategy.class))).thenReturn(queryResponse);
metacard = new MetacardImpl();
metacard.setSourceId(GET_SITENAME);
when(result.getMetacard()).thenReturn(metacard);
Resource resource = mock(Resource.class);
inputStream = new ByteArrayInputStream(GET_STREAM.getBytes(GET_OUTPUT_TYPE));
when(resource.getInputStream()).thenReturn(inputStream);
when(resource.getMimeTypeValue()).thenReturn(GET_MIME_TYPE);
when(resource.getName()).thenReturn(GET_FILENAME);
when(framework.transform(isA(Metacard.class), anyString(), isA(Map.class))).thenReturn(resource);
RESTEndpoint restEndpoint = new RESTEndpoint(framework);
restEndpoint.setTikaMimeTypeResolver(new TikaMimeTypeResolver());
FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
restEndpoint.setFilterBuilder(filterBuilder);
uriInfo = createSpecificUriInfo(LOCAL_RETRIEVE_ADDRESS);
if (local) {
response = restEndpoint.getHeaders(GET_ID, uriInfo, null);
} else {
response = restEndpoint.getHeaders(null, GET_ID, uriInfo, null);
}
return response;
}
use of javax.ws.rs.core.UriInfo in project ddf by codice.
the class AuthenticationEndpointTest method setup.
@Before
public void setup() throws SecurityServiceException, URISyntaxException {
HttpSessionFactory sessionFactory = mock(HttpSessionFactory.class);
HttpSession session = mock(HttpSession.class);
when(session.getAttribute(SecurityConstants.SAML_ASSERTION)).thenReturn(mock(SecurityTokenHolder.class));
when(sessionFactory.getOrCreateSession(any())).thenReturn(session);
policyManager = mock(ContextPolicyManager.class);
securityManager = mock(SecurityManager.class);
authEndpoint = new AuthenticationEndpoint(policyManager, securityManager, sessionFactory);
UriInfo uriInfo = mock(UriInfo.class);
UriBuilder uriBuilder = mock(UriBuilder.class);
when(uriInfo.getBaseUriBuilder()).thenReturn(uriBuilder);
when(uriBuilder.replacePath(anyString())).thenReturn(uriBuilder);
when(uriBuilder.build()).thenReturn(new URI(URL));
authEndpoint.uriInfo = uriInfo;
mockUser(USER_NAME, PASSWORD, REALM);
}
use of javax.ws.rs.core.UriInfo in project ddf by codice.
the class MetricsEndpointTest method testGetMetricsList.
@SuppressWarnings("rawtypes")
@Test
public // @Ignore
void testGetMetricsList() throws Exception {
// Delete all .rrd files in test directory to ensure starting with clean directory
File testDir = new File(TEST_DIR);
File[] fileList = testDir.listFiles();
if (fileList != null) {
for (File file : fileList) {
if (file.isFile()) {
file.delete();
}
}
}
// Create RRD file that Metrics Endpoint will detect
rrdPath = TEST_DIR + "uptime.rrd";
RrdDef def = new RrdDef(rrdPath, 1);
def.addDatasource("uptime", DsType.COUNTER, 90, 0, Double.NaN);
def.addArchive(ConsolFun.TOTAL, 0.5, 1, 60);
rrdDb = RrdDbPool.getInstance().requestRrdDb(def);
UriInfo uriInfo = createUriInfo();
// Get the metrics list from the endpoint
MetricsEndpoint endpoint = getEndpoint();
endpoint.setMetricsDir(TEST_DIR);
Response response = endpoint.getMetricsList(uriInfo);
String metricsList = (String) response.getEntity();
LOGGER.debug("metricsList = {}", metricsList);
cleanupRrd();
// Useful class for simple JSON to handle collections when parsing
// (Called internally by the simple JSON parser.parse(...) method)
ContainerFactory containerFactory = new ContainerFactory() {
public List creatArrayContainer() {
return new LinkedList();
}
public Map createObjectContainer() {
return new LinkedHashMap();
}
};
// Parse the returned JSON text
JSONParser parser = new JSONParser();
Map json = (Map) parser.parse(metricsList, containerFactory);
Set<String> metricNames = (Set<String>) json.keySet();
assertThat(metricNames.size(), equalTo(1));
assertThat(metricNames, hasItem("uptime"));
Iterator metricsIter = json.entrySet().iterator();
// http://<host>:<port>/services/internal/metrics?dateOffset=3600
while (metricsIter.hasNext()) {
Map.Entry entry = (Map.Entry) metricsIter.next();
Map metricTimeRangeLinks = (Map) entry.getValue();
LOGGER.debug("metricTimeRangeLinks = {}", metricTimeRangeLinks);
// Verify each metric name, e.g., "uptime", has all of the time ranges represented
assertThat(metricTimeRangeLinks.containsKey("15m"), is(true));
assertThat(metricTimeRangeLinks.containsKey("1h"), is(true));
// assertThat(metricTimeRangeLinks.containsKey("4h"), is(true));
// assertThat(metricTimeRangeLinks.containsKey("12h"), is(true));
assertThat(metricTimeRangeLinks.containsKey("1d"), is(true));
// assertThat(metricTimeRangeLinks.containsKey("3d"), is(true));
assertThat(metricTimeRangeLinks.containsKey("1w"), is(true));
assertThat(metricTimeRangeLinks.containsKey("1M"), is(true));
assertThat(metricTimeRangeLinks.containsKey("3M"), is(true));
assertThat(metricTimeRangeLinks.containsKey("6M"), is(true));
assertThat(metricTimeRangeLinks.containsKey("1y"), is(true));
Iterator timeRangeLinksIter = metricTimeRangeLinks.entrySet().iterator();
// supported formats and that the correct dateOffset is specified in the hyperlinks
while (timeRangeLinksIter.hasNext()) {
Map.Entry timeRangeLinkEntry = (Map.Entry) timeRangeLinksIter.next();
String timeRange = (String) timeRangeLinkEntry.getKey();
Map<String, String> metricHyperlinks = (Map<String, String>) timeRangeLinkEntry.getValue();
Long dateOffset = MetricsEndpoint.TIME_RANGES.get(timeRange);
assertThat(metricHyperlinks.containsKey("PNG"), is(true));
assertThat(metricHyperlinks.get("PNG"), endsWith("dateOffset=" + dateOffset));
assertThat(metricHyperlinks.containsKey("CSV"), is(true));
assertThat(metricHyperlinks.get("CSV"), endsWith("dateOffset=" + dateOffset));
assertThat(metricHyperlinks.containsKey("XLS"), is(true));
assertThat(metricHyperlinks.get("XLS"), endsWith("dateOffset=" + dateOffset));
}
}
}
Aggregations