List of usage examples for java.util Collections singletonMap
public static <K, V> Map<K, V> singletonMap(K key, V value)
From source file:org.apache.lucene.replicator.http.HttpReplicatorTest.java
private void publishRevision(int id) throws IOException { Document doc = new Document(); writer.addDocument(doc);// w w w .j a v a 2s. c om writer.setLiveCommitData(Collections.singletonMap("ID", Integer.toString(id, 16)).entrySet()); writer.commit(); serverReplicator.publish(new IndexRevision(writer)); }
From source file:io.undertow.server.handlers.path.PathTestCase.java
@Test public void testBasicPathHanding() throws IOException { TestHttpClient client = new TestHttpClient(); try {// w w w.ja v a 2 s.c o m final PathHandler handler = new PathHandler(); handler.addPrefixPath("a", new RemainingPathHandler("/a")); handler.addPrefixPath("/aa", new RemainingPathHandler("/aa")); handler.addExactPath("/aa", new HttpHandler() { @Override public void handleRequest(HttpServerExchange exchange) throws Exception { exchange.getResponseSender().send( "Exact /aa match:" + exchange.getRelativePath() + ":" + exchange.getResolvedPath()); } }); handler.addPrefixPath("/aa/anotherSubPath", new RemainingPathHandler("/aa/anotherSubPath")); final PathHandler sub = new PathHandler(); handler.addPrefixPath("/path", sub); sub.addPrefixPath("/subpath", new RemainingPathHandler("/subpath")); sub.addPrefixPath("/", new RemainingPathHandler("/path")); DefaultServer.setRootHandler(handler); HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/notamatchingpath"); HttpResponse result = client.execute(get); Assert.assertEquals(StatusCodes.NOT_FOUND, result.getStatusLine().getStatusCode()); HttpClientUtils.readResponse(result); get = new HttpGet(DefaultServer.getDefaultServerURL() + "/"); result = client.execute(get); Assert.assertEquals(StatusCodes.NOT_FOUND, result.getStatusLine().getStatusCode()); HttpClientUtils.readResponse(result); runPathTest(client, "/path", "/path", ""); runPathTest(client, "/path/a", "/path", "/a"); runPathTest(client, "/path/subpath", "/subpath", ""); runPathTest(client, "/path/subpath/", "/subpath", "/"); runPathTest(client, "/path/subpath/foo", "/subpath", "/foo"); runPathTest(client, "/a", "/a", ""); runPathTest(client, "/aa/anotherSubPath", "/aa/anotherSubPath", ""); runPathTest(client, "/aa/anotherSubPath/bob", "/aa/anotherSubPath", "/bob"); runPathTest(client, "/aa/b?a=b", "/aa", "/b", Collections.singletonMap("a", "b")); runPathTest(client, "/path/:bar/baz", "/path", "/:bar/baz"); //now test the exact path match get = new HttpGet(DefaultServer.getDefaultServerURL() + "/aa"); result = client.execute(get); Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); Assert.assertEquals("Exact /aa match::/aa", HttpClientUtils.readResponse(result)); } finally { client.getConnectionManager().shutdown(); } }
From source file:com.streamsets.pipeline.stage.executor.shell.TestShellExecutor.java
@Test public void testEnvironmentalVariables() throws Exception { config.script = "echo ${company} > " + handoverFile.getPath(); config.environmentVariables = Collections.singletonMap("company", "${record:value('/company')}"); ShellExecutor executor = new ShellExecutor(config); ExecutorRunner runner = new ExecutorRunner.Builder(ShellDExecutor.class, executor) .setOnRecordError(OnRecordError.STOP_PIPELINE).build(); runner.runInit();/* w ww . j a va2 s . c o m*/ runner.runWrite(ImmutableList.of(getTestRecord())); runner.runDestroy(); assertHandoverFile("StreamSets\n"); }
From source file:org.jasig.portlet.courses.dao.xml.HttpClientCourseOfferingDaoImpl.java
@Override public TermList getTerms(String schoolCode) { final String cacheKey = TERM_LIST_KEY.concat(schoolCode); final Element element = cache.get(cacheKey); if (element != null) { return (TermList) element.getValue(); }// ww w . j a va 2 s . c o m else { final TermList terms = restTemplate.getForObject(termListUrl, TermList.class, Collections.singletonMap("school", schoolCode)); cache.put(new Element(cacheKey, terms)); return terms; } }
From source file:org.elasticsearch.client.StoredScriptsIT.java
public void testDeleteStoredScript() throws Exception { final StoredScriptSource scriptSource = new StoredScriptSource("painless", "Math.log(_score * 2) + params.my_modifier", Collections.singletonMap(Script.CONTENT_TYPE_OPTION, XContentType.JSON.mediaType())); final String script = Strings.toString(scriptSource.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS)); // TODO: change to HighLevel PutStoredScriptRequest when it will be ready // so far - using low-level REST API Response putResponse = adminClient().performRequest("PUT", "/_scripts/" + id, emptyMap(), new StringEntity("{\"script\":" + script + "}", ContentType.APPLICATION_JSON)); assertEquals(putResponse.getStatusLine().getReasonPhrase(), 200, putResponse.getStatusLine().getStatusCode()); assertEquals("{\"acknowledged\":true}", EntityUtils.toString(putResponse.getEntity())); DeleteStoredScriptRequest deleteRequest = new DeleteStoredScriptRequest(id); deleteRequest.masterNodeTimeout("50s"); deleteRequest.timeout("50s"); DeleteStoredScriptResponse deleteResponse = execute(deleteRequest, highLevelClient()::deleteScript, highLevelClient()::deleteScriptAsync); assertThat(deleteResponse.isAcknowledged(), equalTo(true)); GetStoredScriptRequest getRequest = new GetStoredScriptRequest(id); final ElasticsearchStatusException statusException = expectThrows(ElasticsearchStatusException.class, () -> execute(getRequest, highLevelClient()::getScript, highLevelClient()::getScriptAsync)); assertThat(statusException.status(), equalTo(RestStatus.NOT_FOUND)); }
From source file:org.zenoss.zep.dao.impl.EventDetailsConfigDaoImpl.java
@Override @TransactionalRollbackAllExceptions/*from w w w . jav a2 s . c o m*/ public int delete(String eventDetailName) throws ZepException { final Map<String, String> fields = Collections.singletonMap(COLUMN_DETAIL_ITEM_NAME, eventDetailName); final String sql = "DELETE FROM event_detail_index_config WHERE detail_item_name = :detail_item_name"; return this.template.update(sql, fields); }
From source file:org.zenoss.zep.dao.impl.HeartbeatDaoImpl.java
@Override @TransactionalReadOnly//from w w w .ja v a 2 s . c o m public List<DaemonHeartbeat> findByMonitor(String monitor) throws ZepException { final Map<String, String> fields = Collections.singletonMap(COLUMN_MONITOR, monitor); final String sql = "SELECT * FROM daemon_heartbeat WHERE monitor=:monitor"; return this.template.query(sql, MAPPER, fields); }
From source file:io.openshift.booster.BoosterApplicationTest.java
@Test public void testPutNotExisting() { given().contentType(ContentType.JSON).body(Collections.singletonMap("name", "Lemon")).when().put("/0") .then().statusCode(404);/*from w w w .j a v a 2 s . co m*/ }
From source file:io.fabric8.maven.enricher.standard.VolumePermissionEnricherTest.java
@Test public void testAdapt() throws Exception { final TestConfig[] data = new TestConfig[] { new TestConfig(null, null), new TestConfig(null, VolumePermissionEnricher.ENRICHER_NAME, "volumeA"), new TestConfig(null, VolumePermissionEnricher.ENRICHER_NAME, "volumeA", "volumeB") }; for (final TestConfig tc : data) { final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(VolumePermissionEnricher.ENRICHER_NAME, new TreeMap(Collections .singletonMap(VolumePermissionEnricher.Config.permission.name(), tc.permission)))); // Setup mock behaviour new Expectations() { {// w w w.j a v a 2 s. c o m context.getConfig(); result = config; } }; VolumePermissionEnricher enricher = new VolumePermissionEnricher(context); PodTemplateBuilder ptb = createEmptyPodTemplate(); for (String vn : tc.volumeNames) { ptb = addVolume(ptb, vn); } KubernetesListBuilder klb = new KubernetesListBuilder().addToPodTemplateItems(ptb.build()); enricher.adapt(klb); PodTemplate pt = (PodTemplate) klb.buildItem(0); String initContainers = pt.getTemplate().getMetadata().getAnnotations() .get(InitContainerHandler.INIT_CONTAINER_ANNOTATION); boolean shouldHaveInitContainer = tc.volumeNames.length > 0; assertEquals(shouldHaveInitContainer, initContainers != null); if (!shouldHaveInitContainer) { continue; } JSONArray ja = new JSONArray(initContainers); assertEquals(1, ja.length()); JSONObject jo = ja.getJSONObject(0); assertEquals(tc.initContainerName, jo.get("name")); String permission = Strings.isNullOrBlank(tc.permission) ? "777" : tc.permission; JSONArray chmodCmd = new JSONArray(); chmodCmd.put("chmod"); chmodCmd.put(permission); for (String vn : tc.volumeNames) { chmodCmd.put("/tmp/" + vn); } assertEquals(chmodCmd.toString(), jo.getJSONArray("command").toString()); } }
From source file:org.springframework.data.rest.webmvc.alps.AlpsJsonHttpMessageConverter.java
@Override public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {//from ww w .j a v a2 s.com return body instanceof RootResourceInformation ? Collections.singletonMap("alps", converter.convert((RootResourceInformation) body)) : body; }