Refine search
@Test public void shouldForceUserToCallWith() { expected.expectCause( allOf( instanceOf( IllegalArgumentException.class ), hasProperty( "message", is( "You need to call 'with(GraphDatabaseService)' on the template in order to use it" ) ) ) ); TransactionTemplate transactionTemplate = new TransactionTemplate(); transactionTemplate.execute( transaction -> null ); }
@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", nullValue()))); assertThat(jobs.toArray(), hasItemInArray(hasProperty("runOnAllAgents", is(false)))); assertThat(jobs.size(), is(1)); }
@SuppressWarnings({ "rawtypes", "unchecked" }) protected void assertQuerySorting(String property, Query<?, ?> query, Comparable... items) { AbstractQuery<?, ?> queryImpl = (AbstractQuery<?, ?>) query; // save order properties to later reverse ordering List<QueryOrderingProperty> orderProperties = queryImpl.getOrderingProperties(); List<? extends Comparable> sortedList = Arrays.asList(items); Collections.sort(sortedList); List<Matcher<Object>> matchers = new ArrayList<Matcher<Object>>(); for (Comparable comparable : sortedList) { matchers.add(hasProperty(property, equalTo(comparable))); } List<?> instances = query.asc().list(); assertEquals(sortedList.size(), instances.size()); assertThat(instances, contains(matchers.toArray(new Matcher[matchers.size()]))); // reverse ordering for (QueryOrderingProperty orderingProperty : orderProperties) { orderingProperty.setDirection(Direction.DESCENDING); } // reverse matchers Collections.reverse(matchers); instances = query.list(); assertEquals(sortedList.size(), instances.size()); assertThat(instances, contains(matchers.toArray(new Matcher[matchers.size()]))); }
@Test public void artifactBindingNotInSSOList() throws Exception { IdentityZoneHolder.set(otherZone); IDPSSODescriptor idpSSODescriptor = generator.buildIDPSSODescriptor( generator.getEntityBaseURL(), generator.getEntityAlias(), false, Arrays.asList("email") ); assertThat(idpSSODescriptor.getSingleSignOnServices(), not(hasItem(hasProperty("binding", equalTo(SAML2_ARTIFACT_BINDING_URI))))); }
@Test public void testCheckpointingCustomKvStateJobWithCustomClassLoader() throws IOException, ProgramInvocationException { File checkpointDir = FOLDER.newFolder(); File outputDir = FOLDER.newFolder(); final PackagedProgram program = new PackagedProgram( new File(CHECKPOINTING_CUSTOM_KV_STATE_JAR_PATH), new String[] { checkpointDir.toURI().toString(), outputDir.toURI().toString() }); TestStreamEnvironment.setAsContext( miniClusterResource.getMiniCluster(), parallelism, Collections.singleton(new Path(CHECKPOINTING_CUSTOM_KV_STATE_JAR_PATH)), Collections.<URL>emptyList()); expectedException.expectCause( Matchers.<Throwable>hasProperty("cause", isA(SuccessException.class))); program.invokeInteractiveModeForExecution(); }
assertThat(instances, contains( hasProperty(property, equalTo(sortedList.get(0))), hasProperty(property, equalTo(sortedList.get(1))) )); assertThat(instances, contains( hasProperty(property, equalTo(sortedList.get(1))), hasProperty(property, equalTo(sortedList.get(0))) )); assertThat(instances, contains( hasProperty(property, equalTo(sortedList.get(0))), hasProperty(property, equalTo(sortedList.get(1))) )); hasProperty(property, equalTo(sortedList.get(1))), hasProperty(property, equalTo(sortedList.get(0))) )); hasProperty(property, equalTo(sortedList.get(0))), hasProperty(property, equalTo(sortedList.get(1))) )); hasProperty(property, equalTo(sortedList.get(1))), hasProperty(property, equalTo(sortedList.get(0))) )); hasProperty(property, equalTo(sortedList.get(0))), hasProperty(property, equalTo(sortedList.get(1)))
@Test public void shouldCreateAJobForEachAgentIfRunOnAllAgentsIsTrue() throws Exception { Agents agents = new Agents(); agents.add(new AgentConfig("uuid1")); agents.add(new AgentConfig("uuid2")); JobConfig jobConfig = new JobConfig("foo"); jobConfig.setRunOnAllAgents(true); SchedulingContext context = mock(SchedulingContext.class); when(context.getApprovedBy()).thenReturn("chris"); when(context.findAgentsMatching(new ResourceConfigs())).thenReturn(agents); 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("stageName"), jobConfig, context, new TimeProvider(), jobNameGenerator); assertThat(jobs.toArray(), hasItemInArray(hasProperty("name", is("foo-runOnAll-1")))); assertThat(jobs.toArray(), hasItemInArray(hasProperty("agentUuid", is("uuid1")))); assertThat(jobs.toArray(), hasItemInArray(hasProperty("runOnAllAgents", is(true)))); assertThat(jobs.toArray(), hasItemInArray(hasProperty("name", is("foo-runOnAll-1")))); assertThat(jobs.toArray(), hasItemInArray(hasProperty("agentUuid", is("uuid2")))); assertThat(jobs.toArray(), hasItemInArray(hasProperty("runOnAllAgents", is(true)))); assertThat(jobs.size(), is(2)); }
@Test public void testAttributeHamcrestMatchers() throws Exception { mockMvc.perform(get("/")) .andExpect(model().attribute("integer", equalTo(3))) .andExpect(model().attribute("string", allOf(startsWith("a string"), endsWith("value")))) .andExpect(model().attribute("person", hasProperty("name", equalTo("a name")))); }
@Test @SuppressWarnings("unchecked") public void invokesSchedulerForAllEnvironments() throws Exception { when(dataService.listEnvironments(ListEnvironmentsRequest.builder().cluster(CLUSTER).build())) .thenReturn( ListEnvironmentsResponse.builder() .environmentIds(Arrays.asList(FIRST_ENVIRONMENT_ID, SECOND_ENVIRONMENT_ID)) .build()); when(scheduler.callAsync(schedulerArgument.capture())) .thenReturn( CompletableFuture.completedFuture( new SchedulerOutput(CLUSTER_NAME, FIRST_ENVIRONMENT_ID, 1, 1))); ManagerHandler handler = new ManagerHandler(dataService, ecs, scheduler); handler.handleRequest(new ManagerInput(CLUSTER), null); assertThat( schedulerArgument.getAllValues(), contains( hasProperty("environmentId", is(FIRST_ENVIRONMENT_ID)), hasProperty("environmentId", is(SECOND_ENVIRONMENT_ID)))); } }
@Test public void copyingBeaconContainsAllFields() { final Beacon original = new Beacon.Builder().setBluetoothAddress("aa:bb:cc:dd:ee:ff") copied, allOf( hasProperty("bluetoothAddress", equalTo("aa:bb:cc:dd:ee:ff")), hasProperty("bluetoothName", equalTo("Any Bluetooth")), hasProperty("beaconTypeCode", equalTo(1)), hasProperty("dataFields", equalTo(Arrays.asList(2L, 3L))), hasProperty("extraDataFields", equalTo(Arrays.asList(4L, 5L))), hasProperty("id1", equalTo(Identifier.fromInt(6))), hasProperty("id2", equalTo(Identifier.fromInt(7))), hasProperty("id3", equalTo(Identifier.fromInt(8))), hasProperty("manufacturer", equalTo(10)), hasProperty("multiFrameBeacon", equalTo(true)), hasProperty("parserIdentifier", equalTo("Any Parser ID")), hasProperty("rssi", equalTo(-11)), hasProperty("runningAverageRssi", equalTo(-12.3)), hasProperty("serviceUuid", equalTo(13)), hasProperty("txPower", equalTo(14)), hasProperty("packetCount", equalTo(15)), hasProperty("measurementCount", equalTo(16))
@SuppressWarnings("unchecked") @Test public void testExecuteRedirected() throws Exception { final RedirectModifier<Object> modifier = mock(RedirectModifier.class); final Object source1 = new Object(); final Object source2 = new Object(); when(modifier.apply(argThat(hasProperty("source", is(source))))).thenReturn(Lists.newArrayList(source1, source2)); final LiteralCommandNode<Object> concreteNode = subject.register(literal("actual").executes(command)); final LiteralCommandNode<Object> redirectNode = subject.register(literal("redirected").fork(subject.getRoot(), modifier)); final String input = "redirected actual"; final ParseResults<Object> parse = subject.parse(input, source); assertThat(parse.getContext().getRange().get(input), equalTo("redirected")); assertThat(parse.getContext().getNodes().size(), is(1)); assertThat(parse.getContext().getRootNode(), equalTo(subject.getRoot())); assertThat(parse.getContext().getNodes().get(0).getRange(), equalTo(parse.getContext().getRange())); assertThat(parse.getContext().getNodes().get(0).getNode(), is(redirectNode)); assertThat(parse.getContext().getSource(), is(source)); final CommandContextBuilder<Object> parent = parse.getContext().getChild(); assertThat(parent, is(notNullValue())); assertThat(parent.getRange().get(input), equalTo("actual")); assertThat(parent.getNodes().size(), is(1)); assertThat(parse.getContext().getRootNode(), equalTo(subject.getRoot())); assertThat(parent.getNodes().get(0).getRange(), equalTo(parent.getRange())); assertThat(parent.getNodes().get(0).getNode(), is(concreteNode)); assertThat(parent.getSource(), is(source)); assertThat(subject.execute(parse), is(2)); verify(command).run(argThat(hasProperty("source", is(source1)))); verify(command).run(argThat(hasProperty("source", is(source2)))); }
@Test public void copyingBeaconTransfersAllFields() { final Beacon original = new AltBeacon.Builder().setMfgReserved(2) copied, allOf( hasProperty("bluetoothAddress", equalTo("aa:bb:cc:dd:ee:ff")), hasProperty("bluetoothName", equalTo("Any Bluetooth")), hasProperty("beaconTypeCode", equalTo(1)), hasProperty("dataFields", equalTo(Arrays.asList(2L))), hasProperty("extraDataFields", equalTo(Arrays.asList(4L, 5L))), hasProperty("id1", equalTo(Identifier.fromInt(6))), hasProperty("id2", equalTo(Identifier.fromInt(7))), hasProperty("id3", equalTo(Identifier.fromInt(8))), hasProperty("manufacturer", equalTo(10)), hasProperty("multiFrameBeacon", equalTo(true)), hasProperty("parserIdentifier", equalTo("Any Parser ID")), hasProperty("rssi", equalTo(-11)), hasProperty("runningAverageRssi", equalTo(-12.3)), hasProperty("serviceUuid", equalTo(13)), hasProperty("txPower", equalTo(14)), hasProperty("packetCount", equalTo(15)), hasProperty("measurementCount", equalTo(16))
@SuppressWarnings("unchecked") @Test public void testFindTwoInContext() { CacheProvider testCacheProvider1 = addMockProvider("testCacheProvider1"); CacheProvider testCacheProvider2 = addMockProvider("testCacheProvider2"); replay(testCacheProvider1, testCacheProvider2); CacheProvider provider = DefaultCacheProvider.findProvider(); assertThat( provider, anyOf(sameInstance(testCacheProvider1), sameInstance(testCacheProvider2))); String providerName = "testCacheProvider2"; if (provider == testCacheProvider1) { providerName = "testCacheProvider1"; } logging.assertLogged( allOf( hasProperty("level", is(Level.WARNING)), hasProperty( "parameters", arrayContainingInAnyOrder( // Name of the provider being used equalTo(providerName), // Available providers anyOf( equalTo("testCacheProvider1, testCacheProvider2"), equalTo("testCacheProvider2, testCacheProvider1")), // The system property to override equalTo("GEOSERVER_DEFAULT_CACHE_PROVIDER"))))); verify(testCacheProvider1, testCacheProvider2); }
@Test public void parcelingBeaconContainsAllFields() { final Beacon original = new Beacon.Builder().setBluetoothAddress("aa:bb:cc:dd:ee:ff") parceled, allOf( hasProperty("bluetoothAddress", equalTo("aa:bb:cc:dd:ee:ff")), hasProperty("bluetoothName", equalTo("Any Bluetooth")), hasProperty("beaconTypeCode", equalTo(1)), hasProperty("dataFields", equalTo(Arrays.asList(2L, 3L))), hasProperty("extraDataFields", equalTo(Arrays.asList(4L, 5L))), hasProperty("id1", equalTo(Identifier.fromInt(6))), hasProperty("id2", equalTo(Identifier.fromInt(7))), hasProperty("id3", equalTo(Identifier.fromInt(8))), hasProperty("manufacturer", equalTo(10)), hasProperty("multiFrameBeacon", equalTo(true)), hasProperty("parserIdentifier", equalTo("Any Parser ID")), hasProperty("rssi", equalTo(-11)), hasProperty("runningAverageRssi", equalTo(-12.3)), hasProperty("serviceUuid", equalTo(13)), hasProperty("txPower", equalTo(14)), hasProperty("packetCount", equalTo(15)), hasProperty("measurementCount", equalTo(16))
@Test public void testAssertFail() throws Throwable { final Logger log = createMock("log", Logger.class); fail("Expected Assertion Exception"); } catch (AssertionError ex) { assertThat(ex, hasProperty("message", containsString("Expected record"))); } finally { verify(log, desc, base);
@Test public void testCanSerializeParcelable() { org.robolectric.shadows.ShadowLog.stream = System.err; parceled, allOf( hasProperty("bluetoothAddress", equalTo("aa:bb:cc:dd:ee:ff")), hasProperty("bluetoothName", equalTo("Any Bluetooth")), hasProperty("beaconTypeCode", equalTo(1)), hasProperty("dataFields", equalTo(Arrays.asList(2L))), hasProperty("extraDataFields", equalTo(Arrays.asList(4L, 5L))), hasProperty("id1", equalTo(Identifier.fromInt(6))), hasProperty("id2", equalTo(Identifier.fromInt(7))), hasProperty("id3", equalTo(Identifier.fromInt(8))), hasProperty("manufacturer", equalTo(10)), hasProperty("multiFrameBeacon", equalTo(true)), hasProperty("parserIdentifier", equalTo("Any Parser ID")), hasProperty("rssi", equalTo(-11)), hasProperty("runningAverageRssi", equalTo(-12.3)), hasProperty("serviceUuid", equalTo(13)), hasProperty("txPower", equalTo(14)), hasProperty("mfgReserved", equalTo(2)), hasProperty("packetCount", equalTo(15)), hasProperty("measurementCount", equalTo(16))
@Test public void aFileConfigurationLocationIsCorrectlyParsed() { assertThat(underTest.create(PROJECT, "LOCAL_FILE:/Users/aUser/Projects/aProject/checkstyle/cs-rules.xml:Some checkstyle rules"), allOf( hasProperty("location", is(oneOf( "/Users/aUser/Projects/aProject/checkstyle/cs-rules.xml", "\\Users\\aUser\\Projects\\aProject\\checkstyle\\cs-rules.xml"))), hasProperty("description", is("Some checkstyle rules")))); }
@Test public void defaultViewResolver() throws Exception { standaloneSetup(new PersonController()).build() .perform(get("/person/Corea")) .andExpect(model().attribute("person", hasProperty("name", equalTo("Corea")))) .andExpect(status().isOk()) .andExpect(forwardedUrl("person/show")); // InternalResourceViewResolver }
@Test public void lockRequestIsWrite() throws InterruptedException { when(LOCK_CLIENT.lock(CLIENT, LOCK_NAME)).thenAnswer((invocation) -> { LockRequest request = (LockRequest) invocation.getArguments()[1]; assertThat(request.getLocks(), contains(hasProperty("lockMode", is(LockMode.WRITE)))); return null; }); LOCK_CLIENT.lock(CLIENT, LOCK_NAME); }
@Test public void healthException() throws Exception { // Generate a unique in-process server name. String serverName = InProcessServerBuilder.generateName(); HealthCheckAggregator hca = mock(HealthCheckAggregator.class); CompletableFuture<HealthCheckStatus> hcsf = mock(CompletableFuture.class); when(hcsf.get()).thenThrow(InterruptedException.class); when(hca.check()).thenReturn(hcsf); HealthServiceImpl healthyService = new HealthServiceImpl(hca); addService(serverName, healthyService); HealthGrpc.HealthBlockingStub blockingStub = HealthGrpc.newBlockingStub( // Create a client channel and register for automatic graceful shutdown. grpcCleanup.register(InProcessChannelBuilder.forName(serverName).directExecutor().build())); thrown.expect(StatusRuntimeException.class); thrown.expect(hasProperty("status", is(Status.INTERNAL))); blockingStub.check(HealthCheckRequest.newBuilder().build()); }