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.pentaho.reporting.platform.plugin.async.ExecutorIT.java
@Test public void testRecalc() throws IOException, ExecutionException, InterruptedException { try {/* w ww . j ava 2 s .c o m*/ final IPluginManager pluginManager = mock(IPluginManager.class); PentahoSystem.registerObject(pluginManager, IPluginManager.class); when(pluginManager.getPluginSetting("reporting", "settings/query-limit", "0")).thenReturn("50"); final StandaloneSession session = new StandaloneSession("test"); PentahoSessionHolder.setSession(session); final UUID uuid = UUID.randomUUID(); final AsyncJobFileStagingHandler asyncJobFileStagingHandler = new AsyncJobFileStagingHandler(session); simpleReportingComponent .setReportDefinitionPath("target/test/resource/solution/test/reporting/100rows.prpt"); simpleReportingComponent.setInputs(Collections.singletonMap("query-limit", 500)); executor.addTask( new PentahoAsyncReportExecution("target/test/resource/solution/test/reporting/100rows.prpt", simpleReportingComponent, asyncJobFileStagingHandler, session, UUID.randomUUID().toString(), new AuditWrapper()), session, uuid); IAsyncReportState reportState = executor.getReportState(uuid, session); while (reportState.getTotalRows() < 1) { reportState = executor.getReportState(uuid, session); } assertEquals(100, reportState.getTotalRows()); final UUID recalculate = executor.recalculate(uuid, session); assertFalse(uuid.equals(recalculate)); IAsyncReportState recalcState = executor.getReportState(recalculate, session); while (recalcState.getTotalRows() < 1) { recalcState = executor.getReportState(recalculate, session); } assertEquals(100, recalcState.getTotalRows()); } finally { PentahoSessionHolder.removeSession(); } }
From source file:org.tradex.validation.trade.TradeImportValidation.java
/** * <p>Validates various bits of the passed trade.</p> * <p>If validation fails, the exchange's exception set in order to setup a <b>recoverable</b> error. * For example, an ISIN may be invalid because it has not been registered in the ISIN database yet, * but once it is, the trade import will succeed on retry.</p> * <p>Once the trade has failed {@link #maxRetries} times, the exchange will have its <b>fault</b> flag set, * indicating an unrecoverable error.</p> * @param tradeExchange the exchange containing the trade to validate * @throws TradeImportBusinessException Thrown on business validation failures *//*from w w w .j a v a2 s. c om*/ @Handler public void validateTrade(Exchange tradeExchange) throws TradeImportBusinessException { ITrade trade = tradeExchange.getIn().getBody(ITrade.class); try { if (1 > jdbcTemplate.queryForInt("SELECT COUNT(*) FROM ISIN WHERE ISIN = :isin", Collections.singletonMap("isin", trade.getIsin()))) { throw new Exception("Invalid ISIN [" + trade.getIsin() + "]"); } } catch (Exception ex) { TradeImportBusinessException tibe = new TradeImportBusinessException( "Failed to validate Trade [" + trade + "]", ex); // final int retries = getRetryCount(tradeExchange);//tradeExchange.getProperty(Exchange.REDELIVERY_COUNTER, 0, Integer.class); // log.warn("\n\t======================\n\tFailed trade retry count: [" + retries + "]\n\t======================\n"); // if(retries>=maxRetries) { // Message fault = tradeExchange.getOut(); // fault.setFault(true); // } // tradeExchange.setException(tibe); throw tibe; // int retries = getRetryCount(tradeExchange); // log.warn("\n\t======================\n\tFailed trade retry count: [" + retries + "]\n\t======================\n"); // tradeExchange.setException(tibe); // if(retries>=maxRetries) { // Message fault = tradeExchange.getOut(); // fault.setFault(true); // fault.setBody(tibe); // } else { // tradeExchange.setException(tibe); // } } }
From source file:org.apache.beam.sdk.io.elasticsearch.ElasticSearchIOTestUtils.java
/** Inserts the given number of test documents into Elasticsearch. */ static void insertTestDocuments(ConnectionConfiguration connectionConfiguration, long numDocs, RestClient restClient) throws IOException { List<String> data = ElasticSearchIOTestUtils.createDocuments(numDocs, ElasticSearchIOTestUtils.InjectionMode.DO_NOT_INJECT_INVALID_DOCS); StringBuilder bulkRequest = new StringBuilder(); int i = 0;/*from www. j a v a 2s . c o m*/ for (String document : data) { bulkRequest.append(String.format( "{ \"index\" : { \"_index\" : \"%s\", \"_type\" : \"%s\", \"_id\" : \"%s\" } }%n%s%n", connectionConfiguration.getIndex(), connectionConfiguration.getType(), i++, document)); } String endPoint = String.format("/%s/%s/_bulk", connectionConfiguration.getIndex(), connectionConfiguration.getType()); HttpEntity requestBody = new NStringEntity(bulkRequest.toString(), ContentType.APPLICATION_JSON); Response response = restClient.performRequest("POST", endPoint, Collections.singletonMap("refresh", "true"), requestBody); ElasticsearchIO.checkForErrors(response, ElasticsearchIO.getBackendVersion(connectionConfiguration)); }
From source file:com.hp.autonomy.frontend.find.idol.configuration.IdolConfigurationController.java
@RequestMapping(value = "/securitytypes", method = RequestMethod.GET) public Map<String, List<String>> getSecurityTypes(@RequestParam final int port, @RequestParam final String host, @RequestParam final AciServerDetails.TransportProtocol protocol) { if (port <= 0 || host == null || protocol == null) { throw new IllegalArgumentException("Host, port and protocol must be supplied."); }//from w w w . j a va2 s . com final List<SecurityType> types = communityService .getSecurityTypes(new AciServerDetails(protocol, host, port)); final List<String> typeNames = new ArrayList<>(); for (final SecurityType type : types) { typeNames.add(type.getName()); } return Collections.singletonMap("securityTypes", typeNames); }
From source file:ch.cyberduck.core.sds.triplecrypt.CryptoWriteFeatureTest.java
@Test public void testWrite() throws Exception { final Host host = new Host(new SDSProtocol(), "duck.ssp-europe.eu", new Credentials( System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key"))); final SDSSession session = new SDSSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path room = new Path("CD-TEST-ENCRYPTED", EnumSet.of(Path.Type.directory, Path.Type.volume, Path.Type.vault)); final byte[] content = RandomUtils.nextBytes(32769); final TransferStatus status = new TransferStatus(); status.setLength(content.length);// w w w . j a v a 2 s. c o m final Path test = new Path(room, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file, Path.Type.decrypted)); final SDSEncryptionBulkFeature bulk = new SDSEncryptionBulkFeature(session); bulk.pre(Transfer.Type.upload, Collections.singletonMap(test, status), new DisabledConnectionCallback()); final CryptoWriteFeature writer = new CryptoWriteFeature(session, new SDSWriteFeature(session)); final StatusOutputStream<VersionId> out = writer.write(test, status, new DisabledConnectionCallback()); assertNotNull(out); new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out); final VersionId version = out.getStatus(); assertNotNull(version); assertTrue(new DefaultFindFeature(session).find(test)); assertEquals(content.length, new SDSAttributesFinderFeature(session).find(test).getSize()); final byte[] compare = new byte[content.length]; final InputStream stream = new CryptoReadFeature(session, new SDSReadFeature(session)).read(test, new TransferStatus(), new ConnectionCallback() { @Override public void warn(final Host bookmark, final String title, final String message, final String defaultButton, final String cancelButton, final String preference) throws ConnectionCanceledException { // } @Override public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) throws LoginCanceledException { return new VaultCredentials("ahbic3Ae"); } }); IOUtils.readFully(stream, compare); stream.close(); assertArrayEquals(content, compare); new SDSDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:org.cloudfoundry.identity.uaa.security.web.UaaRequestMatcherTests.java
@Test public void pathMatcherMatchesExpectedPathsAndRequestParameters() throws Exception { // Accept only JSON UaaRequestMatcher matcher = new UaaRequestMatcher("/somePath"); matcher.setAccept(Arrays.asList(MediaType.APPLICATION_JSON.toString())); matcher.setParameters(Collections.singletonMap("response_type", "token")); assertTrue(matcher.matches(request("/somePath", null, "response_type", "token"))); }
From source file:org.commonjava.aprox.depgraph.rest.ResolverController.java
public String resolveGraph(final String from, final String groupId, final String artifactId, final String version, final boolean recurse, final String workspaceId, final Map<String, String[]> params) throws AproxWorkflowException { URI source;// w w w . j a v a 2 s. co m try { source = sourceManager.createSourceURI(from); } catch (final CartoDataException e) { throw new AproxWorkflowException("Invalid source specification: {}. Reason: {}", e, from, e.getMessage()); } if (source == null) { final String message = String.format("Invalid source format: '%s'. Use the form: '%s' instead.", from, sourceManager.getFormatHint()); logger.warn(message); throw new AproxWorkflowException(ApplicationStatus.BAD_REQUEST.code(), message); } final ProjectVersionRef ref = new ProjectVersionRef(groupId, artifactId, version); final AggregationOptions options = createAggregationOptions(params, source); Set<ProjectVersionRef> resolved; ViewParams resolvedParams = null; try { resolvedParams = ops.resolve(workspaceId, options, ref); resolved = resolvedParams.getRoots(); if (resolved == null || resolved.isEmpty()) { resolved = Collections.singleton(ref); } return serializer.writeValueAsString(Collections.singletonMap("resolvedTopLevelGAVs", resolved)); } catch (final CartoDataException e) { throw new AproxWorkflowException("Failed to resolve graph: {} from: {}. Reason: {}", e, ref, from, e.getMessage()); } catch (final JsonProcessingException e) { throw new AproxWorkflowException("Failed to serialize to JSON: %s", e, e.getMessage()); } }
From source file:io.pivotal.strepsirrhini.chaosloris.web.ApplicationControllerTest.java
@Test public void create() throws Exception { UUID applicationId = UUID.randomUUID(); when(this.applicationRepository.saveAndFlush(new Application(applicationId))).then(invocation -> { Application application = invocation.getArgumentAt(0, Application.class); application.setId(1L);/* ww w . j a va 2s .c o m*/ return application; }); this.mockMvc .perform(post("/applications").contentType(APPLICATION_JSON) .content(asJson(Collections.singletonMap("applicationId", applicationId.toString())))) .andExpect(status().isCreated()) .andExpect(header().string("Location", "http://localhost/applications/1")); }
From source file:io.openshift.booster.BoosterApplicationTest.java
@Test public void testPut() { Fruit cherry = fruitRepository.save(new Fruit("Cherry")); given().contentType(ContentType.JSON).body(Collections.singletonMap("name", "Lemon")).when() .put(String.valueOf(cherry.getId())).then().statusCode(200).body("id", is(cherry.getId())) .body("name", is("Lemon")); }