@Test @ElasticsearchIndex(indexName = "twitter") public void updateWithValidParameters() { String script = "{\n" + " \"script\" : \"ctx._source.tags += tag\",\n" + " \"params\" : {\n" + " \"tag\" : \"blue\"\n" + " }\n" + "}"; try { Index index = new Index.Builder("{\"user\":\"kimchy\", \"tags\":\"That is test\"}") .index("twitter") .type("tweet") .id("1") .build(); index.addParameter(Parameters.REFRESH, true); client.execute(index); JestResult result = client.execute(new Update.Builder(script).index("twitter").type("tweet").id("1").build()); assertNotNull(result); assertTrue(result.isSucceeded()); JestResult getResult = client.execute(new Get.Builder("1").index("twitter").type("tweet").build()); assertEquals("That is testblue", ((Map) getResult.getValue("_source")).get("tags")); } catch (Exception e) { fail("Failed during the update with valid parameters. Exception:" + e.getMessage()); } }
@Test public void informationModel() throws Exception { String serviceUrl = "http://service.url"; GridDataService dataService = new GridDataService(); dataService.setUrl(serviceUrl); getGridServiceDao().save(dataService); Metadata meta = new Metadata(); try { meta.dmodel = MetadataUtils.deserializeDomainModel(new FileReader("test/data/cabioModelSnippet.xml")); meta.smeta = MetadataUtils.deserializeServiceMetadata( new FileReader("test/data/cabioServiceMetadata.xml")); } catch (Exception ex) { fail("Error deserializing test data: " + ex.getMessage()); ex.printStackTrace(); } try { getMetadataListener().loadMetadata(dataService, meta); } catch (Exception ex) { fail("Error loading metadata: " + ex.getMessage()); ex.printStackTrace(); } ServiceMetadataCatalogEntryBuilder b = (ServiceMetadataCatalogEntryBuilder) getApplicationContext().getBean("serviceMetadataCatalogEntryBuilder"); final GridServiceEndPointCatalogEntry endpointCe = b.build(dataService); assertTrue(endpointCe instanceof GridDataServiceEndPointCatalogEntry); InformationModelCatalogEntryDao infoDao = (InformationModelCatalogEntryDao) TestDB.getApplicationContext().getBean("informationModelCatalogEntryDao"); assertEquals(1, infoDao.getAll().size()); InformationModelCatalogEntry infoEntry = (InformationModelCatalogEntry) infoDao.getAll().get(0); infoEntry.setAuthor(pUser); infoDao.save(infoEntry); GridServiceEndPointCatalogEntry endpointCe2 = b.build(dataService); assertEquals(endpointCe.getId(), endpointCe2.getId()); assertEquals("Duplicate Information Model CE is being created", 1, infoDao.getAll().size()); }
/** Verify constructor */ @Test public void testConstructor() { try { new SCMProjectProperty(null); fail("Null should be handled by SCMProjectProperty constructor."); } catch (Exception e) { assertEquals(BaseProjectProperty.INVALID_JOB_EXCEPTION, e.getMessage()); } }
@Test public void shouldNotThrowExceptionIfXmlnsNotRecognized() { Map<String, String> motherFormValuesWithoutXmlns = motherFormValues( "94d5374f-290e-409f-bc57-86c2e4bcc43f", "89fda0284e008d2e0c980fb13fa0e5bb"); motherFormValuesWithoutXmlns.put("xmlns", "randomurl"); try { careService.processAndSaveForms( motherFormValuesWithoutXmlns, new ArrayList<Map<String, String>>()); } catch (Exception e) { fail("The exception should not have been thrown: " + e.getMessage()); } }
@Test @ElasticsearchIndex( indexName = "histogram_facet", mappings = { @ElasticsearchMapping( typeName = "document", properties = { @ElasticsearchMappingField( name = "quantity", store = ElasticsearchMappingField.Store.Yes, type = ElasticsearchMappingField.Types.Integer) }) }) public void testQuery() { String query = "{\n" + " \"query\" : {\n" + " \"match_all\" : {}\n" + " },\n" + " \"facets\" : {\n" + " \"histo1\" : {\n" + " \"histogram\" : {\n" + " \"field\" : \"quantity\",\n" + " \"interval\" : 100\n" + " }\n" + " }\n" + " }\n" + "}"; try { for (int i = 0; i < 2; i++) { Index index = new Index.Builder("{\"quantity\":\"910\"}") .index("histogram_facet") .type("document") .build(); index.addParameter(Parameters.REFRESH, true); client.execute(index); } Index index = new Index.Builder("{\"quantity\":\"800\"}") .index("histogram_facet") .type("document") .build(); index.addParameter(Parameters.REFRESH, true); client.execute(index); index = new Index.Builder("{\"quantity\":\"1110\"}") .index("histogram_facet") .type("document") .build(); index.addParameter(Parameters.REFRESH, true); client.execute(index); Search search = (Search) new Search.Builder(query) .addIndexName("histogram_facet") .addIndexType("document") .build(); JestResult result = client.execute(search); List<HistogramFacet> histogramFacets = result.getFacets(HistogramFacet.class); assertEquals(1, histogramFacets.size()); HistogramFacet histogramFacetFirst = histogramFacets.get(0); assertEquals("histo1", histogramFacetFirst.getName()); List<HistogramFacet.Histogram> histograms = histogramFacetFirst.getHistograms(); assertEquals(3, histograms.size()); assertTrue(1L == histograms.get(0).getCount()); assertTrue(800L == histograms.get(0).getKey()); assertTrue(2L == histograms.get(1).getCount()); assertTrue(900L == histograms.get(1).getKey()); assertTrue(1L == histograms.get(2).getCount()); assertTrue(1100L == histograms.get(2).getKey()); } catch (Exception e) { fail("Failed during facet tests " + e.getMessage()); } }