@Test public void refresh() throws Exception { final Reddit reddit = new Reddit(); PublishSubject<Reddit> subject = PublishSubject.create(); Mockito.doReturn(subject.asObservable().toList()) .when(mRepository) .getReddits(Mockito.anyString()); mViewModel.refresh(); Mockito.verify(mRepository).getReddits("test"); Assert.assertThat(mViewModel.errorText.get(), IsNull.nullValue()); Assert.assertThat(mViewModel.isLoading.get(), Is.is(true)); subject.onNext(reddit); subject.onCompleted(); Assert.assertThat(mViewModel.isLoading.get(), Is.is(false)); Assert.assertThat(mViewModel.reddits, IsCollectionContaining.hasItems(reddit)); }
public void testCustomCharFilterInRequest() throws Exception { Map<String, Object> charFilterSettings = new HashMap<>(); charFilterSettings.put("type", "mapping"); charFilterSettings.put("mappings", new String[]{"ph => f", "qu => q"}); AnalyzeResponse analyzeResponse = client().admin().indices() .prepareAnalyze() .setText("jeff quit phish") .setTokenizer("keyword") .addCharFilter(charFilterSettings) .setExplain(true) .get(); assertThat(analyzeResponse.detail().analyzer(), IsNull.nullValue()); //charfilters assertThat(analyzeResponse.detail().charfilters().length, equalTo(1)); assertThat(analyzeResponse.detail().charfilters()[0].getName(), equalTo("_anonymous_charfilter_[0]")); assertThat(analyzeResponse.detail().charfilters()[0].getTexts().length, equalTo(1)); assertThat(analyzeResponse.detail().charfilters()[0].getTexts()[0], equalTo("jeff qit fish")); //tokenizer assertThat(analyzeResponse.detail().tokenizer().getName(), equalTo("keyword")); assertThat(analyzeResponse.detail().tokenizer().getTokens().length, equalTo(1)); assertThat(analyzeResponse.detail().tokenizer().getTokens()[0].getTerm(), equalTo("jeff qit fish")); assertThat(analyzeResponse.detail().tokenizer().getTokens()[0].getStartOffset(), equalTo(0)); assertThat(analyzeResponse.detail().tokenizer().getTokens()[0].getEndOffset(), equalTo(15)); assertThat(analyzeResponse.detail().tokenizer().getTokens()[0].getPositionLength(), equalTo(1)); }
@Test public void refreshError() throws Exception { PublishSubject<Reddit> subject = PublishSubject.create(); Mockito.doReturn(subject.asObservable().toList()) .when(mRepository) .getReddits(Mockito.anyString()); mViewModel.refresh(); Mockito.verify(mRepository).getReddits("test"); Assert.assertThat(mViewModel.errorText.get(), IsNull.nullValue()); Assert.assertThat(mViewModel.isLoading.get(), Is.is(true)); subject.onError(new Exception("error text")); Assert.assertThat(mViewModel.isLoading.get(), Is.is(false)); Assert.assertThat(mViewModel.errorText.get(), IsEqual.equalTo("error text")); }
@Test public void testRenameCluster() { Tree<ClusterVO, ItemAssocVO<Integer,Integer>> clusters = clusterService.getClustersForTenant(1); ClusterVO root = clusters.getRoot(); printCluster(clusters, root); assertThat(clusters.getHeight(), is(2)); assertThat(clusters.getChildCount(root), is(2)); assertThat(clusters.getVertexCount(), is(5)); assertThat(clusterService.loadCluster(1,"CLUSTER3"), IsNull.nullValue()); try { clusterService.renameCluster(1, "CLUSTER1", "CLUSTER3"); } catch (ClusterException ce) { logger.info(ce); } printCluster(clusters, root); assertThat(clusters.getHeight(), is(2)); assertThat(clusters.getChildCount(root), is(2)); assertThat(clusters.getVertexCount(), is(5)); assertThat(clusterService.loadCluster(1,"CLUSTER3"), IsNull.notNullValue()); }
@Test public void shouldSupportImgRefLink() throws IOException { final InputStream stream = getClass().getClassLoader().getResourceAsStream("withImgRefLink.md"); assertThat( stream, IsNull.notNullValue()); final InputStream inputStream = Site.processMarkdown(stream, "Test IMG"); assertThat( inputStream, IsNull.notNullValue()); final String converted = IOUtils.toString(inputStream); assertThat(converted, containsString("!http://www.lewe.com/wp-content/uploads/2016/03/conf-icon-64.png|alt=\"conf-icon\"|title=\"My conf-icon\"!")); assertThat(converted, containsString("!conf-icon-64.png|alt=\"conf-icon\"|title=\"My conf-icon\"!")); assertThat(converted, containsString("!conf-icon-64.png|alt=\"conf-icon\"!")); assertThat(converted, containsString("!http://www.lewe.com/wp-content/uploads/2016/03/conf-icon-64.png|alt=\"conf-icon-y\"|title=\"My conf-icon\"!")); assertThat(converted, containsString("!http://www.lewe.com/wp-content/uploads/2016/03/conf-icon-64.png|alt=\"conf-icon-y1\"!")); assertThat(converted, containsString("!conf-icon-64.png|alt=\"conf-icon-y2\"!")); assertThat(converted, containsString("!conf-icon-64.png|alt=\"conf-icon-none\"!")); }
@Test public void shouldSupportSimpleNode() throws IOException { final InputStream stream = getClass().getClassLoader().getResourceAsStream("simpleNodes.md"); assertThat( stream, IsNull.notNullValue()); final InputStream inputStream = Site.processMarkdown(stream, "Test"); assertThat( inputStream, IsNull.notNullValue()); final String converted = IOUtils.toString(inputStream); assertThat("All forms of HRules should be supported", converted, containsString("----\n1\n----\n2\n----\n3\n----\n4\n----")); /* only when Extensions.SMARTS is activated assertThat(converted, containsString("…")); assertThat(converted, containsString("–")); assertThat(converted, containsString("—")); */ assertThat(converted, containsString("Forcing a line-break\nNext line in the list")); assertThat(converted, containsString(" ")); }
@Test public void shouldCreateSpecificNoticeBlock() throws IOException { final InputStream stream = getClass().getClassLoader().getResourceAsStream("createSpecificNoticeBlock.md"); assertThat( stream, IsNull.notNullValue()); final InputStream inputStream = Site.processMarkdown(stream, "Test Macro"); assertThat( inputStream, IsNull.notNullValue()); final String converted = IOUtils.toString(inputStream); assertThat(converted, containsString("{info:title=About me}\n")); assertThat("Should not generate unneeded param 'title'", converted, not(containsString("{note:title=}\n"))); assertThat(converted, containsString("{tip:title=About you}\n")); assertThat(converted, containsString("bq. test a simple blockquote")); assertThat(converted, containsString("{quote}\n")); assertThat(converted, containsString("* one\n* two")); assertThat(converted, containsString("a *strong* and _pure_ feeling")); }
@Before @Override public void initService() throws Exception { super.initService(); try { // SSL Implementation final SSLSocketFactory sslSocketFactory = SSLFactories.newInstance( new YesTrustManager()); Assert.assertThat(sslSocketFactory, IsNull.notNullValue()); final X509TrustManager trustManager = new YesTrustManager(); final HostnameVerifier hostnameVerifier = new YesHostnameVerifier(); service.client .hostnameVerifier(hostnameVerifier) .sslSocketFactory(sslSocketFactory, trustManager) ; } catch (Exception ex) { throw new IllegalStateException(ex); } }
/** * clientIdを作成する. * @return clientId * @throws Exception clientIdの作成に失敗した場合に発生 */ private String createClientId() throws Exception { String uri = "http://localhost:4035/gotapi/authorization/grant"; Map<String, String> headers = new HashMap<>(); headers.put("Origin", getOrigin()); HttpUtil.Response response = HttpUtil.get(uri, headers); assertThat(response, is(notNullValue())); JSONObject json = response.getJSONObject(); assertThat(json, is(notNullValue())); assertThat(json.getInt("result"), is(0)); assertThat(json.getString("clientId"), is(IsNull.notNullValue())); return json.getString("clientId"); }
@Test public void buyOrderOfCustomerWithEnoughCashAndKnownStock() { Mockito.when(stockRepository.findOneByName(Matchers.anyString())).thenReturn(Optional.of(new Stock("TSLA", 10))); Mockito.when(customerRepository.findOne(Matchers.anyLong())).thenReturn(new Customer("Test user", 500)); BuyOrder optional = buyOrderServiceActivator.processOrder(new BuyOrder("TSLA", 10, 1)); assertThat(optional, is(IsNull.notNullValue())); Mockito.verify(stockRepository).findOneByName("TSLA"); Mockito.verify(customerRepository).findOne(1L); ArgumentCaptor<Customer> customerArgumentCaptor = ArgumentCaptor.forClass(Customer.class); Mockito.verify(customerRepository).save(customerArgumentCaptor.capture()); Customer customer = customerArgumentCaptor.getValue(); assertThat(customer.getFreeCash(), is(400)); assertThat(customer.getName(), is("Test user")); Mockito.verifyNoMoreInteractions(customerRepository, stockRepository); }
@Test public void shouldEasilyDoSimpleAtomicMutationMulti() throws Exception { ByteBuffer regionLocation = ByteBuffer.wrap(Bytes.toBytes("testTable")); RegionSpecifier regionSpecifier = new RegionSpecifier(RegionSpecifier.RegionSpecifierType.REGION_NAME, regionLocation); context.checking(new Expectations() { { oneOf(hRegionInterface).processRowsWithLocks(with(any(MultiRowMutationProcessor.class))); } }); MutationProto mutation = ProtobufUtil.toMutation(MutationProto.MutationType.PUT, new Put(Bytes.toBytes("fakeRow"))); RegionActionResult actions = hRegionBridge.processRegionAction(new RegionAction(regionSpecifier, true, Arrays.asList(new Action(0, mutation, null)))); assertThat(actions.getException(), IsNull.nullValue()); assertThat(actions.getResultOrExceptionList().size(), is(1)); }
@Test public void shouldEasilyDoAtomicMutationOnlyMultiPut() throws Exception { ByteBuffer regionLocation = ByteBuffer.wrap(Bytes.toBytes("testTable")); RegionSpecifier regionSpecifier = new RegionSpecifier(RegionSpecifier.RegionSpecifierType.REGION_NAME, regionLocation); context.checking(new Expectations() { { oneOf(hRegionInterface).processRowsWithLocks(with(any(MultiRowMutationProcessor.class))); } }); MutationProto mutation = ProtobufUtil.toMutation(MutationProto.MutationType.PUT, new Put(Bytes.toBytes("fakeRow"))); RegionActionResult actions = hRegionBridge.processRegionAction(new RegionAction(regionSpecifier, true, Arrays.asList( new Action(0, mutation, null), new Action(1, mutation, null), new Action(2, mutation, null)) )); assertThat(actions.getException(), IsNull.nullValue()); assertThat(actions.getResultOrExceptionList().size(), is(3)); }
@Test public void shouldEasilyDoAtomicMutationOnlyMultiDelete() throws Exception { ByteBuffer regionLocation = ByteBuffer.wrap(Bytes.toBytes("testTable")); RegionSpecifier regionSpecifier = new RegionSpecifier(RegionSpecifier.RegionSpecifierType.REGION_NAME, regionLocation); context.checking(new Expectations() { { oneOf(hRegionInterface).processRowsWithLocks(with(any(MultiRowMutationProcessor.class))); } }); MutationProto mutation = ProtobufUtil.toMutation(MutationProto.MutationType.DELETE, new Delete(Bytes.toBytes("fakeRow"))); RegionActionResult actions = hRegionBridge.processRegionAction(new RegionAction(regionSpecifier, true, Arrays.asList( new Action(0, mutation, null), new Action(1, mutation, null), new Action(2, mutation, null)) )); assertThat(actions.getException(), IsNull.nullValue()); assertThat(actions.getResultOrExceptionList().size(), is(3)); }
@Test public void shouldFailWhenWeTryToAtomicMutateAndGet() throws Exception { ByteBuffer regionLocation = ByteBuffer.wrap(Bytes.toBytes("testTable")); RegionSpecifier regionSpecifier = new RegionSpecifier(RegionSpecifier.RegionSpecifierType.REGION_NAME, regionLocation); MutationProto mutation = ProtobufUtil.toMutation(MutationProto.MutationType.DELETE, new Delete(Bytes.toBytes("fakeRow"))); Get get = ProtobufUtil.toGet(new org.apache.hadoop.hbase.client.Get(Bytes.toBytes("fakeRow2")), false); Get exists = ProtobufUtil.toGet(new org.apache.hadoop.hbase.client.Get(Bytes.toBytes("fakeRow2")), true); RegionActionResult actions = hRegionBridge.processRegionAction(new RegionAction(regionSpecifier, true, Arrays.asList( new Action(0, mutation, get), new Action(1, mutation, exists)) )); assertThat(actions.getException(), IsNull.notNullValue()); assertThat(actions.getResultOrExceptionList().size(), is(0)); }
@Test public void shouldEasilyDoSimpleMutationMulti() throws Exception { ByteBuffer regionLocation = ByteBuffer.wrap(Bytes.toBytes("testTable")); RegionSpecifier regionSpecifier = new RegionSpecifier(RegionSpecifier.RegionSpecifierType.REGION_NAME, regionLocation); context.checking(new Expectations() { { oneOf(hRegionInterface).put(with(any(Put.class))); } }); MutationProto mutation = ProtobufUtil.toMutation(MutationProto.MutationType.PUT, new Put(Bytes.toBytes("fakeRow"))); RegionActionResult actions = hRegionBridge.processRegionAction(new RegionAction(regionSpecifier, false, Arrays.asList(new Action(0, mutation, null)))); assertThat(actions.getException(), IsNull.nullValue()); assertThat(actions.getResultOrExceptionList().size(), is(1)); }
@Test public void shouldEasilyDoMutationOnlyMultiPut() throws Exception { ByteBuffer regionLocation = ByteBuffer.wrap(Bytes.toBytes("testTable")); RegionSpecifier regionSpecifier = new RegionSpecifier(RegionSpecifier.RegionSpecifierType.REGION_NAME, regionLocation); context.checking(new Expectations() { { exactly(3).of(hRegionInterface).put(with(any(Put.class))); } }); MutationProto mutation = ProtobufUtil.toMutation(MutationProto.MutationType.PUT, new Put(Bytes.toBytes("fakeRow"))); RegionActionResult actions = hRegionBridge.processRegionAction(new RegionAction(regionSpecifier, false, Arrays.asList( new Action(0, mutation, null), new Action(1, mutation, null), new Action(2, mutation, null)) )); assertThat(actions.getException(), IsNull.nullValue()); assertThat(actions.getResultOrExceptionList().size(), is(3)); }
@Test public void shouldEasilyDoMutationOnlyMultiDelete() throws Exception { ByteBuffer regionLocation = ByteBuffer.wrap(Bytes.toBytes("testTable")); RegionSpecifier regionSpecifier = new RegionSpecifier(RegionSpecifier.RegionSpecifierType.REGION_NAME, regionLocation); context.checking(new Expectations() { { oneOf(hRegionInterface).delete(with(any(Delete.class))); oneOf(hRegionInterface).delete(with(any(Delete.class))); oneOf(hRegionInterface).delete(with(any(Delete.class))); } }); MutationProto mutation = ProtobufUtil.toMutation(MutationProto.MutationType.DELETE, new Delete(Bytes.toBytes("fakeRow"))); RegionActionResult actions = hRegionBridge.processRegionAction(new RegionAction(regionSpecifier, false, Arrays.asList( new Action(0, mutation, null), new Action(1, mutation, null), new Action(2, mutation, null)) )); assertThat(actions.getException(), IsNull.nullValue()); assertThat(actions.getResultOrExceptionList().size(), is(3)); }
@Test public void shouldBeAbleToProcessMultiRowNonAtomicPut() throws Exception { ByteBuffer regionLocation = ByteBuffer.wrap(Bytes.toBytes("testTable")); RegionSpecifier regionSpecifier = new RegionSpecifier(RegionSpecifier.RegionSpecifierType.REGION_NAME, regionLocation); MutationProto mutation = ProtobufUtil.toMutation(MutationProto.MutationType.PUT, new Put(Bytes.toBytes("fakeRow"))); MutationProto mutation2 = ProtobufUtil.toMutation(MutationProto.MutationType.PUT, new Put(Bytes.toBytes("fakeRow2"))); context.checking(new Expectations() { { exactly(3).of(hRegionInterface).put(with(any(Put.class))); } }); RegionActionResult actions = hRegionBridge.processRegionAction(new RegionAction(regionSpecifier, false, Arrays.asList( new Action(0, mutation, null), new Action(1, mutation, null), new Action(2, mutation2, null)) )); assertThat(actions.getException(), IsNull.nullValue()); assertThat(actions.getResultOrExceptionList().size(), is(3)); }
@Test public void shouldFailWhenWeTryToMutateAndGet() throws Exception { ByteBuffer regionLocation = ByteBuffer.wrap(Bytes.toBytes("testTable")); RegionSpecifier regionSpecifier = new RegionSpecifier(RegionSpecifier.RegionSpecifierType.REGION_NAME, regionLocation); MutationProto mutation = ProtobufUtil.toMutation(MutationProto.MutationType.DELETE, new Delete(Bytes.toBytes("fakeRow"))); Get get = ProtobufUtil.toGet(new org.apache.hadoop.hbase.client.Get(Bytes.toBytes("fakeRow2")), false); Get exists = ProtobufUtil.toGet(new org.apache.hadoop.hbase.client.Get(Bytes.toBytes("fakeRow2")), true); RegionActionResult actions = hRegionBridge.processRegionAction(new RegionAction(regionSpecifier, true, Arrays.asList( new Action(0, mutation, get), new Action(1, mutation, exists)) )); assertThat(actions.getException(), IsNull.notNullValue()); assertThat(actions.getResultOrExceptionList().size(), is(0)); }
/** * Test for checking if the value changes in case of a thrown exception * * @throws Exception */ @Test public void testDontChangeValueOnException() throws Exception { // set valid value final Double targetValue = 50.5; taskMock.setPercentComplete(targetValue); assertThat(taskMock.getPercentComplete(), IsNot.not(IsNull.nullValue())); assertThat(taskMock.getPercentComplete(), IsInstanceOf.instanceOf(Double.class)); assertThat(taskMock.getPercentComplete(), IsEqual.equalTo(targetValue)); final Double invalidValue = -0.1; try { taskMock.setPercentComplete(invalidValue); } catch (IllegalArgumentException ex) { // ignored } assertThat(taskMock.getPercentComplete(), IsNot.not(IsNull.nullValue())); assertThat(taskMock.getPercentComplete(), IsInstanceOf.instanceOf(Double.class)); assertThat(taskMock.getPercentComplete(), IsEqual.equalTo(targetValue)); }
/** * service-function to test the response for creating a node as child of the parentId * @param parentId parentId of the new task * @param node the node to create * @return the sysUID of the new node * @throws Exception io-Exceptions possible */ public String testCreateNode(final String parentId, final BaseNode node) throws Exception { // request MockHttpServletRequestBuilder req = MockMvcRequestBuilders.post("/nodes/create/" + node.getClassName() + "/" + parentId); // set params req.content(convertObjectToJsonBytes(node)); // set contenttype; req.contentType(APPLICATION_JSON_UTF8); ResultActions res = testBaseRequest(req); // check data res.andExpect(jsonPath("$.node.name", is(node.getName()))) .andExpect(jsonPath("$.node.sysUID", IsNull.notNullValue())); // create JSON from String String response = res.andReturn().getResponse().getContentAsString(); String sysUID = JsonPath.read(response, "$.node.sysUID"); return sysUID; }
/** * @throws IOException * @throws SolrServerException * @see DATASOLR-72 */ @Test public void schemaShouldBeUpdatedPriorToSavingEntity() throws SolrServerException, IOException { NamedList<Object> nl = new NamedList<Object>(); nl.add("json", "{ \"schema\" : {\"name\" : \"core1\" }, \"version\" : 1.5 }"); Mockito.when(solrServerMock.request(Mockito.any(SolrSchemaRequest.class))).thenReturn(nl); Mockito.when(solrServerMock.request(Mockito.any(SolrSchemaRequest.class))).thenReturn(nl); solrTemplate = new SolrTemplate(solrServerMock, "core1"); solrTemplate.setSchemaCreationFeatures(Collections.singletonList(Feature.CREATE_MISSING_FIELDS)); solrTemplate.afterPropertiesSet(); solrTemplate.saveBean(new DocumentWithIndexAnnotations()); ArgumentCaptor<SolrRequest> requestCaptor = ArgumentCaptor.forClass(SolrRequest.class); Mockito.verify(solrServerMock, Mockito.times(3)).request(requestCaptor.capture()); SolrRequest capturedRequest = requestCaptor.getValue(); Assert.assertThat(capturedRequest.getMethod(), IsEqual.equalTo(SolrRequest.METHOD.POST)); Assert.assertThat(capturedRequest.getPath(), IsEqual.equalTo("/schema/fields")); Assert.assertThat(capturedRequest.getContentStreams(), IsNull.notNullValue()); }
@Test public void testFunctionQueryInFieldProjection() { ExampleSolrBean bean1 = new ExampleSolrBean("id-1", "one", null); bean1.setStore("45.17614,-93.87341"); ExampleSolrBean bean2 = new ExampleSolrBean("id-2", "one two", null); bean2.setStore("40.7143,-74.006"); solrTemplate.saveBeans(Arrays.asList(bean1, bean2)); solrTemplate.commit(); Query q = new SimpleQuery("*:*"); q.addProjectionOnField(new DistanceField("distance", "store", new Point(45.15, -93.85))); Page<ExampleSolrBean> result = solrTemplate.queryForPage(q, ExampleSolrBean.class); for (ExampleSolrBean bean : result) { Assert.assertThat(bean.getDistance(), IsNull.notNullValue()); } }
/** * @see DATASOLR-142 */ @Test public void testDistaneFunctionWithGeoLocationQueryInFieldProjection() { ExampleSolrBean bean1 = new ExampleSolrBean("id-1", "one", null); bean1.setStore("45.17614,-93.87341"); ExampleSolrBean bean2 = new ExampleSolrBean("id-2", "one two", null); bean2.setStore("40.7143,-74.006"); solrTemplate.saveBeans(Arrays.asList(bean1, bean2)); solrTemplate.commit(); Query q = new SimpleQuery("*:*"); q.addProjectionOnField(new DistanceField("distance", "store", new GeoLocation(45.15, -93.85))); Page<ExampleSolrBean> result = solrTemplate.queryForPage(q, ExampleSolrBean.class); for (ExampleSolrBean bean : result) { Assert.assertThat(bean.getDistance(), IsNull.notNullValue()); } }
@Test public void shouldPopulateModificationDetailsForPackageMaterial() { String userName = "user"; String comment = "comments"; Date checkinDate = new Date(System.currentTimeMillis()); String revision = "package-1.0.0.rpm"; Element modificationsTag = DocumentHelper.createDocument().addElement("modifications"); Modifications modifications = new Modifications(new Modification(userName, comment, null, checkinDate, revision)); XmlWriterContext writerContext = mock(XmlWriterContext.class); when(writerContext.getBaseUrl()).thenReturn("http://someurl:8153/go"); new PipelineXmlViewModel.PackageXmlViewModel(MaterialsMother.packageMaterial()).populateXmlForModifications(modifications, writerContext, modificationsTag); Element changeSet = modificationsTag.element("changeset"); assertThat(changeSet, is(not(IsNull.nullValue()))); assertThat(changeSet.attributeValue("changesetUri"), is("http://someurl:8153/go/api/materials/1/changeset/package-1.0.0.rpm.xml")); assertThat(changeSet.element("user").getText(), is(userName)); assertThat(changeSet.element("revision").getText(), is(revision)); assertThat(changeSet.element("checkinTime").getText(), is(DateUtils.formatISO8601(checkinDate))); assertThat(changeSet.element("message").getText(), is(comment)); }
@Test public void shouldCreateASingleJobIfRunOnAllAgentsIsFalse() throws Exception { JobConfig jobConfig = new JobConfig("foo"); SchedulingContext context = mock(SchedulingContext.class); when(context.getEnvironmentVariablesConfig()).thenReturn(new EnvironmentVariablesConfig()); when(context.overrideEnvironmentVariables(any(EnvironmentVariablesConfig.class))).thenReturn(context); RunOnAllAgents.CounterBasedJobNameGenerator jobNameGenerator = new RunOnAllAgents.CounterBasedJobNameGenerator(CaseInsensitiveString.str(jobConfig.name())); JobInstances jobs = instanceFactory.createJobInstance(new CaseInsensitiveString("someStage"), jobConfig, new DefaultSchedulingContext(), new TimeProvider(), jobNameGenerator); assertThat(jobs.toArray(), hasItemInArray(hasProperty("name", is("foo")))); assertThat(jobs.toArray(), hasItemInArray(hasProperty("agentUuid", IsNull.nullValue()))); assertThat(jobs.toArray(), hasItemInArray(hasProperty("runOnAllAgents", is(false)))); assertThat(jobs.size(), is(1)); }
public void testDetailAnalyze() throws Exception { assertAcked(prepareCreate("test").addAlias(new Alias("alias")) .setSettings( Settings.builder() .put("index.analysis.char_filter.my_mapping.type", "mapping") .putArray("index.analysis.char_filter.my_mapping.mappings", "PH=>F") .put("index.analysis.analyzer.test_analyzer.type", "custom") .put("index.analysis.analyzer.test_analyzer.position_increment_gap", "100") .put("index.analysis.analyzer.test_analyzer.tokenizer", "standard") .putArray("index.analysis.analyzer.test_analyzer.char_filter", "my_mapping") .putArray("index.analysis.analyzer.test_analyzer.filter", "snowball"))); ensureGreen(); for (int i = 0; i < 10; i++) { AnalyzeResponse analyzeResponse = admin().indices().prepareAnalyze().setIndex(indexOrAlias()).setText("THIS IS A PHISH") .setExplain(true).addCharFilter("my_mapping").setTokenizer("keyword").addTokenFilter("lowercase").get(); assertThat(analyzeResponse.detail().analyzer(), IsNull.nullValue()); //charfilters assertThat(analyzeResponse.detail().charfilters().length, equalTo(1)); assertThat(analyzeResponse.detail().charfilters()[0].getName(), equalTo("my_mapping")); assertThat(analyzeResponse.detail().charfilters()[0].getTexts().length, equalTo(1)); assertThat(analyzeResponse.detail().charfilters()[0].getTexts()[0], equalTo("THIS IS A FISH")); //tokenizer assertThat(analyzeResponse.detail().tokenizer().getName(), equalTo("keyword")); assertThat(analyzeResponse.detail().tokenizer().getTokens().length, equalTo(1)); assertThat(analyzeResponse.detail().tokenizer().getTokens()[0].getTerm(), equalTo("THIS IS A FISH")); assertThat(analyzeResponse.detail().tokenizer().getTokens()[0].getStartOffset(), equalTo(0)); assertThat(analyzeResponse.detail().tokenizer().getTokens()[0].getEndOffset(), equalTo(15)); //tokenfilters assertThat(analyzeResponse.detail().tokenfilters().length, equalTo(1)); assertThat(analyzeResponse.detail().tokenfilters()[0].getName(), equalTo("lowercase")); assertThat(analyzeResponse.detail().tokenfilters()[0].getTokens().length, equalTo(1)); assertThat(analyzeResponse.detail().tokenfilters()[0].getTokens()[0].getTerm(), equalTo("this is a fish")); assertThat(analyzeResponse.detail().tokenfilters()[0].getTokens()[0].getPosition(), equalTo(0)); assertThat(analyzeResponse.detail().tokenfilters()[0].getTokens()[0].getStartOffset(), equalTo(0)); assertThat(analyzeResponse.detail().tokenfilters()[0].getTokens()[0].getEndOffset(), equalTo(15)); } }
public void testDetailAnalyzeWithNoIndex() throws Exception { //analyzer only AnalyzeResponse analyzeResponse = client().admin().indices().prepareAnalyze("THIS IS A TEST") .setExplain(true).setAnalyzer("simple").get(); assertThat(analyzeResponse.detail().tokenizer(), IsNull.nullValue()); assertThat(analyzeResponse.detail().tokenfilters(), IsNull.nullValue()); assertThat(analyzeResponse.detail().charfilters(), IsNull.nullValue()); assertThat(analyzeResponse.detail().analyzer().getName(), equalTo("simple")); assertThat(analyzeResponse.detail().analyzer().getTokens().length, equalTo(4)); }
@Test public void testSetLogger() { PagerAdaptersLogging.setLogger(null); assertThat(PagerAdaptersLogging.getLogger(), is(IsNot.not(IsNull.nullValue()))); final Logger logger = new SimpleLogger(Log.DEBUG); PagerAdaptersLogging.setLogger(logger); assertThat(PagerAdaptersLogging.getLogger(), is(logger)); }
@Test public void testSetLogger() { FragmentsLogging.setLogger(null); assertThat(FragmentsLogging.getLogger(), is(IsNot.not(IsNull.nullValue()))); final Logger logger = new SimpleLogger(Log.DEBUG); FragmentsLogging.setLogger(logger); assertThat(FragmentsLogging.getLogger(), is(logger)); }
/** * Method: parse(State<E> s) */ @Test public void simple() throws Exception { State<Character, Integer, Integer> state = newState("left right left right"); Parsec<String, Character> parser = skip1(text("left")); String re = parser.parse(state); Assert.assertThat("Expect string \"left\".", re, IsNull.nullValue()); }
/** * Тестовый метод. */ @Test public void whenPollElementShouldReturnAndDeleteIt() { SimpleQueue<Integer> queue = new SimpleQueue<>(); queue.push(1); queue.push(2); queue.push(3); assertThat((Integer) queue.poll(), is(1)); assertThat((Integer) queue.poll(), is(2)); assertThat((Integer) queue.poll(), is(3)); assertThat((Integer) queue.poll(), is(IsNull.nullValue())); }
/** * Must be ignored because i got * * java.lang.NoClassDefFoundError: org/bsc/maven/reporting/model/Site * at org.bsc.maven.reporting.test.SiteTest.jaxbTest(SiteTest.java:30) * * @throws Exception */ @Test @Ignore public void jaxbTest() throws Exception { java.io.File basepath = new java.io.File("src/site/confluence/home.confluence"); java.net.URI relativeURI = new java.net.URI("template.confluence"); System.out.printf("uri=[%s]\n", basepath.toURI().resolve(relativeURI) ); JAXBContext jc = JAXBContext.newInstance(Site.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); Object result = unmarshaller.unmarshal( getClass().getClassLoader().getResourceAsStream("site.xml")); Assert.assertThat(result, IsNull.notNullValue()); Assert.assertThat(result, IsInstanceOf.instanceOf(Site.class)); Site site = (Site) result; site.setBasedir( basepath ); Assert.assertThat(site.getHome().getUri(), IsNull.notNullValue()); Assert.assertThat(site.getHome().getName(), IsEqual.equalTo("home")); Assert.assertThat(site.getHome().getSource().getName(), IsEqual.equalTo("home.confluence")); Assert.assertThat(site.getHome(), IsNull.notNullValue()); Assert.assertThat(site.getHome().getAttachments(), IsNull.notNullValue()); Assert.assertThat(site.getHome().getAttachments().isEmpty(), Is.is(false)); Assert.assertThat(site.getHome().getChildren(), IsNull.notNullValue()); Assert.assertThat(site.getHome().getChildren().isEmpty(), Is.is(false)); Assert.assertThat(site.getLabels().isEmpty(), Is.is(false)); for( String label : site.getLabels() ) { System.out.printf( "label=[%s]\n", label); } }
@Test public void shouldSupportReferenceNode() throws IOException { final InputStream stream = getClass().getClassLoader().getResourceAsStream("withRefLink.md"); assertThat( stream, IsNull.notNullValue()); final InputStream inputStream = Site.processMarkdown(stream, "Test"); assertThat( inputStream, IsNull.notNullValue()); final String converted = IOUtils.toString(inputStream); assertThat(converted, containsString("[rel|Test - relativeagain]")); assertThat(converted, containsString("[more complex google|http://google.com|Other google]")); assertThat(converted, containsString("[google|http://google.com]")); }
@Test public void getOrCreatePageAndStoreStorage() throws Exception { final String spaceKey = "TEST"; final String parentPageTitle = "Home"; final String title = "MyPage3"; final Model.Page p = service.getOrCreatePage(spaceKey, parentPageTitle, title); int version = p.getVersion(); Assert.assertThat( p, IsNull.notNullValue()); Assert.assertThat( p.getSpace(), IsEqual.equalTo("TEST")); Assert.assertThat( version > 0, Is.is(true)); final String content = new StringBuilder() .append("<h1>") .append("TEST ") .append(System.currentTimeMillis()) .append("</h1>") .append("<hr/>") .append("<b>'storage' \"storage\"</b>") .toString(); final Model.Page p1 = service.storePage(p, new Storage(content, Storage.Representation.STORAGE)); Assert.assertThat( p1, IsNull.notNullValue()); Assert.assertThat( p1.getSpace(), IsEqual.equalTo("TEST")); Assert.assertThat( p1.getVersion(), IsEqual.equalTo(version+1)); }
@Test public void getStorageFormat() throws IOException { final String credential = Credentials.basic("admin", "admin"); final HttpUrl url = new HttpUrl.Builder() .scheme(SCHEME) .host(HOST) .port(PORT) .addPathSegments("plugins/viewstorage/viewpagestorage.action") .addQueryParameter("pageId", "1867778") .build(); final Request req = new Request.Builder() .header("Authorization", credential) .url( url ) .get() .build(); final Response res = client.build().newCall(req).execute(); Assert.assertThat( res, IsNull.notNullValue()); Assert.assertThat( res.isSuccessful(), Is.is(true)); final ResponseBody body = res.body(); Assert.assertThat( body, IsNull.notNullValue()); System.out.printf( "BODY\n%s\n", body.string() ); }
private Response deletePage( String id ) { try { final String credential = Credentials.basic("admin", "admin"); final HttpUrl.Builder url = new HttpUrl.Builder() .scheme(SCHEME) .host(HOST) .port(PORT) .addPathSegments("rest/api/content") ; final Request req1 = new Request.Builder() .header("Authorization", credential) .url( url.addPathSegment(id).build() ) .delete() .build(); final Response res1 = client.build().newCall(req1).execute(); Assert.assertThat( res1, IsNull.notNullValue()); Assert.assertThat( res1.code(), IsEqual.equalTo(204)); return res1; } catch (IOException ex) { Assert.fail( ex.getMessage() ); } return null; }
private Matcher<T> bestMatcher() { for (Matcher<T> matcher : elements) { if (matcher.getClass() != IsNull.class) { return matcher; } } return equalTo(null); }