List of usage examples for java.util Collections singletonMap
public static <K, V> Map<K, V> singletonMap(K key, V value)
From source file:net.ontopia.topicmaps.nav2.taglibs.TMvalue.TologQueryTag.java
@Override public Collection process(Collection tmObjects) throws JspException { if (query == null) throw new NavigatorCompileException("TologQueryTag: Ambiguous attribute " + "settings."); // try to retrieve default value from ContextManager ContextTag contextTag = FrameworkUtils.getContextTag(pageContext); // Get the ContextManager ContextManagerIF ctxtMgr = contextTag.getContextManager(); // Create a map for the context Map argmap = new ContextManagerMapWrapper(ctxtMgr); // get topicmap object on which we should compute TopicMapIF topicmap = contextTag.getTopicMap(); if (topicmap == null) throw new NavigatorRuntimeException("TologQueryTag found no topic map."); // Get the result from the QueryProcessor QueryProcessorIF q_processor = (implementation == null ? QueryUtils.createQueryProcessor(topicmap) : QueryUtils.createQueryProcessor(topicmap, Collections .singletonMap("net.ontopia.topicmaps.query.core.QueryProcessorIF", implementation))); if (rulesfile != null) { ServletContext ctxt = pageContext.getServletContext(); try {//ww w .j a va2 s . c o m q_processor.load(new InputStreamReader(ctxt.getResourceAsStream(rulesfile))); } catch (IOException e) { throw JSPEngineWrapper.getJspException("Problem loading tolog rules file: " + rulesfile, e); } catch (InvalidQueryException e) { throw JSPEngineWrapper.getJspException("Problem loading tolog rules file: " + rulesfile, e); } } try { // produce list of maps return getMapCollection(q_processor.execute(query, argmap)); } catch (InvalidQueryException e) { log.debug("Parsing of query '" + query + "' failed with message: " + e); throw new NavigatorRuntimeException(e); } }
From source file:com.consol.citrus.admin.connector.WebSocketPushMessageListenerTest.java
@Test public void testOnOutboundMessage() throws Exception { Message outbound = new DefaultMessage("Hello Citrus!"); reset(restTemplate, context);//from w w w .j av a2 s . c o m when(restTemplate.exchange(eq("http://localhost:8080/connector/message/outbound?processId=MySampleTest"), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class))).thenAnswer(invocation -> { HttpEntity request = (HttpEntity) invocation.getArguments()[2]; Assert.assertEquals(request.getBody().toString(), outbound.toString()); return ResponseEntity.ok().build(); }); when(context.getVariables()) .thenReturn(Collections.singletonMap(Citrus.TEST_NAME_VARIABLE, "MySampleTest")); when(context.getVariable(Citrus.TEST_NAME_VARIABLE)).thenReturn("MySampleTest"); pushMessageListener.onOutboundMessage(outbound, context); verify(restTemplate).exchange(eq("http://localhost:8080/connector/message/outbound?processId=MySampleTest"), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class)); }
From source file:org.jboss.as.test.integration.logging.profiles.NonExistingProfileTestCase.java
@BeforeClass public static void deploy() throws Exception { deploy(createDeployment(Collections.singletonMap("Logging-Profile", "non-existing-profile")), RUNTIME_NAME); }
From source file:org.elasticsearch.upgrades.RecoveryIT.java
public void testHistoryUUIDIsGenerated() throws Exception { final String index = "index_history_uuid"; if (CLUSTER_TYPE == ClusterType.OLD) { Settings.Builder settings = Settings.builder() .put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1) .put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 1) // if the node with the replica is the first to be restarted, while a replica is still recovering // then delayed allocation will kick in. When the node comes back, the master will search for a copy // but the recovering copy will be seen as invalid and the cluster health won't return to GREEN // before timing out .put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "100ms"); createIndex(index, settings.build()); } else if (CLUSTER_TYPE == ClusterType.UPGRADED) { ensureGreen(index);//from w w w . ja va2 s. c o m Response response = client().performRequest("GET", index + "/_stats", Collections.singletonMap("level", "shards")); assertOK(response); ObjectPath objectPath = ObjectPath.createFromResponse(response); List<Object> shardStats = objectPath.evaluate("indices." + index + ".shards.0"); assertThat(shardStats, hasSize(2)); String expectHistoryUUID = null; for (int shard = 0; shard < 2; shard++) { String nodeID = objectPath.evaluate("indices." + index + ".shards.0." + shard + ".routing.node"); String historyUUID = objectPath .evaluate("indices." + index + ".shards.0." + shard + ".commit.user_data.history_uuid"); assertThat("no history uuid found for shard on " + nodeID, historyUUID, notNullValue()); if (expectHistoryUUID == null) { expectHistoryUUID = historyUUID; } else { assertThat("different history uuid found for shard on " + nodeID, historyUUID, equalTo(expectHistoryUUID)); } } } }
From source file:hudson.matrix.MatrixTest.java
/** * Test that project level permissions apply to child configurations as well. *///from w w w . j av a2s. c o m @Issue("JENKINS-9293") @Test public void configurationACL() throws Exception { j.jenkins.setAuthorizationStrategy(new ProjectMatrixAuthorizationStrategy()); MatrixProject mp = j.createProject(MatrixProject.class); mp.setAxes(new AxisList(new Axis("foo", "a", "b"))); MatrixConfiguration mc = mp.getItem("foo=a"); assertNotNull(mc); SecurityContextHolder.clearContext(); assertFalse(mc.getACL().hasPermission(Item.READ)); mp.addProperty(new AuthorizationMatrixProperty( Collections.singletonMap(Item.READ, Collections.singleton("anonymous")))); // Project-level permission should apply to single configuration too: assertTrue(mc.getACL().hasPermission(Item.READ)); }
From source file:com.smartitengineering.cms.spi.impl.content.JasperGeneratorTest.java
@Test public void testJasperRepGeneration() throws IOException { TypeRepresentationGenerator generator = new JasperRepresentationGenerator(); final RepresentationTemplate template = mockery.mock(RepresentationTemplate.class); WorkspaceAPIImpl impl = new WorkspaceAPIImpl() { @Override/*from w w w . j a v a 2 s. co m*/ public RepresentationTemplate getRepresentationTemplate(WorkspaceId id, String name) { return template; } }; impl.setRepresentationGenerators(Collections.singletonMap(TemplateType.JASPER, generator)); RepresentationProvider provider = new RepresentationProviderImpl(); final WorkspaceAPI api = impl; registerBeanFactory(api); final Content content = mockery.mock(Content.class, "Content"); final Field field = mockery.mock(Field.class, "FIeld"); final FieldValue value = mockery.mock(FieldValue.class, "FieldValue"); final Map<String, Field> fieldMap = mockery.mock(Map.class, "Field Map"); final ContentType type = mockery.mock(ContentType.class, "Content Type"); final Map<String, RepresentationDef> reps = mockery.mock(Map.class, "repMap"); final RepresentationDef def = mockery.mock(RepresentationDef.class, "RepDef"); final ContentId contentId = mockery.mock(ContentId.class, "Content Id"); final String[] formats = new String[] { JasperRepresentationGenerator.DOCX, JasperRepresentationGenerator.ODS, JasperRepresentationGenerator.ODT, JasperRepresentationGenerator.PDF, JasperRepresentationGenerator.RTF, JasperRepresentationGenerator.TXT, JasperRepresentationGenerator.XLS, JasperRepresentationGenerator.XML }; final Map<String, String> map = new HashMap<String, String>(); mockery.checking(new Expectations() { { exactly(1 + formats.length).of(template).getTemplateType(); will(returnValue(TemplateType.JASPER)); exactly(1 + formats.length).of(template).getTemplate(); will(returnValue(IOUtils .toByteArray(getClass().getClassLoader().getResourceAsStream("scripts/jasper/test.xml")))); exactly(1 + formats.length).of(template).getName(); will(returnValue(REP_NAME)); exactly(1 + formats.length).of(value).getValue(); will(returnValue(CONTENT)); exactly(1 + formats.length).of(field).getValue(); will(returnValue(value)); exactly(1 + formats.length).of(fieldMap).get(with(Expectations.<String>anything())); will(returnValue(field)); exactly(1 + formats.length).of(content).getFields(); will(returnValue(fieldMap)); exactly(3 + formats.length * 3).of(content).getContentDefinition(); will(returnValue(type)); exactly(3 + formats.length * 3).of(content).getContentId(); will(returnValue(contentId)); final WorkspaceId wId = mockery.mock(WorkspaceId.class); exactly(2 + formats.length * 2).of(contentId).getWorkspaceId(); will(returnValue(wId)); exactly(2 + formats.length * 2).of(type).getRepresentationDefs(); will(returnValue(reps)); exactly(2 + formats.length * 2).of(reps).get(with(REP_NAME)); will(returnValue(def)); exactly(1 + formats.length).of(def).getParameters(); will(returnValue(map)); exactly(1 + formats.length).of(def).getMIMEType(); will(returnValue(GroovyGeneratorTest.MIME_TYPE)); exactly(1 + formats.length).of(type).getDisplayName(); will(returnValue("Display Name")); final ResourceUri rUri = mockery.mock(ResourceUri.class); exactly(1 + formats.length).of(def).getResourceUri(); will(returnValue(rUri)); exactly(1 + formats.length).of(rUri).getValue(); will(returnValue("iUri")); } }); map.put("output", "csv"); Representation representation = provider.getRepresentation(REP_NAME, type, content); FileOutputStream stream = new FileOutputStream(new File("./target/test.csv")); stream.write(representation.getRepresentation()); stream.close(); FileInputStream inputStream = new FileInputStream(new File("./src/test/resources/scripts/jasper/test.csv")); Assert.assertArrayEquals(IOUtils.toByteArray(inputStream), representation.getRepresentation()); inputStream.close(); for (String format : formats) { map.clear(); map.put("output", format); representation = provider.getRepresentation(REP_NAME, type, content); stream = new FileOutputStream(new File("./target/test." + format)); stream.write(representation.getRepresentation()); stream.close(); } }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation.java
/** * Check for XSS for a single field. Returns NO_ERROR if there * are no errors so it can be added to a map with putAll() *///from w w w . ja va2s . c o m protected Map<String, String> checkSubmissionForField(String fieldName, MultiValueEditSubmission editSub) { if (fieldName == null || fieldName.isEmpty() || editSub == null) return NO_ERROR; if (editSub.getLiteralsFromForm() != null && editSub.getLiteralsFromForm().containsKey(fieldName)) { String error = null; try { error = literalHasXSS(editSub.getLiteralsFromForm().get(fieldName)); } catch (ScanException e) { error = e.getMessage(); } catch (PolicyException e) { error = e.getMessage(); } if (error != null) { return Collections.singletonMap(fieldName, XSS_ERROR_MESSAGE + " " + error); } else { return NO_ERROR; } } else if (editSub.getUrisFromForm() != null && editSub.getUrisFromForm().containsKey(fieldName)) { String error; try { error = uriHasXSS(editSub.getUrisFromForm().get(fieldName)); } catch (ScanException e) { error = e.getMessage(); } catch (PolicyException e) { error = e.getMessage(); } if (error != null) { return Collections.singletonMap(fieldName, XSS_ERROR_MESSAGE + " " + error); } else { return NO_ERROR; } } else { //field wasn't in submission return NO_ERROR; } }
From source file:com.smartitengineering.cms.spi.impl.hbase.Utils.java
public static void organizeByPrefixOnString(Map<String, byte[]> fieldMap, Map<String, Map<String, byte[]>> fieldsByName, char separator) { logger.debug("Organize by their prefix so that each field cells can be processed at once"); for (Entry<String, byte[]> entry : fieldMap.entrySet()) { final String key = entry.getKey(); final int indexOfFirstColon = key.indexOf(separator); if (indexOfFirstColon > -1) { final String fieldName = key.substring(0, indexOfFirstColon); Map<String, byte[]> fieldCells = fieldsByName.get(fieldName); if (fieldCells == null) { fieldCells = new LinkedHashMap<String, byte[]>(); fieldsByName.put(fieldName, fieldCells); }/* w w w. j ava 2 s . co m*/ fieldCells.put(entry.getKey(), entry.getValue()); } else { fieldsByName.put(key, Collections.singletonMap(entry.getKey(), entry.getValue())); } } }
From source file:de.tud.inf.db.sparqlytics.bench.LDBCBenchmark.java
@Test public void testQ01() throws Exception { test("01", Collections.singletonMap("date", "2014-01-01")); }
From source file:ch.cyberduck.core.openstack.SwiftDistributionConfiguration.java
@Override public void write(final Path file, final Distribution configuration, final LoginCallback prompt) throws BackgroundException { final Path container = containerService.getContainer(file); try {/*from w ww . j a va2s .c o m*/ if (StringUtils.isNotBlank(configuration.getIndexDocument())) { session.getClient().updateContainerMetadata(regionService.lookup(container), container.getName(), Collections.singletonMap("X-Container-Meta-Web-Index", configuration.getIndexDocument())); } try { final CDNContainer info = session.getClient().getCDNContainerInfo(regionService.lookup(container), container.getName()); if (log.isDebugEnabled()) { log.debug(String.format("Found existing CDN configuration %s", info)); } } catch (NotFoundException e) { // Not found. if (log.isDebugEnabled()) { log.debug(String.format("Enable CDN configuration for %s", container)); } session.getClient().cdnEnableContainer(regionService.lookup(container), container.getName()); } // Toggle content distribution for the container without changing the TTL expiration if (log.isDebugEnabled()) { log.debug(String.format("Update CDN configuration for %s", container)); } session.getClient().cdnUpdateContainer(regionService.lookup(container), container.getName(), -1, configuration.isEnabled(), configuration.isLogging()); } catch (GenericException e) { throw new SwiftExceptionMappingService().map("Cannot write CDN configuration", e); } catch (IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot write CDN configuration", e); } }