Refine search
private void checkValidationForModes(IdentityZone zone, IdentityZoneConfiguration config) throws InvalidIdentityZoneConfigurationException, InvalidIdentityZoneDetailsException { for (IdentityZoneValidator.Mode mode : Arrays.asList(CREATE, MODIFY, DELETE)) { reset(zoneConfigurationValidator); when(zoneConfigurationValidator.validate(any(), any())).thenReturn(config); validator.validate(zone, mode); verify(zoneConfigurationValidator, times(1)).validate(same(zone), same(mode)); } } }
/** Standard flow */ @Test public void testStartStage() throws Exception { final ApplicationScope context = mock( ApplicationScope.class ); //mock returning a mock mutation when we do a log entry write final MvccLogEntrySerializationStrategy logStrategy = mock( MvccLogEntrySerializationStrategy.class ); final ArgumentCaptor<MvccLogEntry> logEntry = ArgumentCaptor.forClass( MvccLogEntry.class ); final MutationBatch mutation = mock( MutationBatch.class ); final UUIDService uuidService = mock ( UUIDService.class ); when( logStrategy.write( same( context ), logEntry.capture() ) ).thenReturn( mutation ); //set up the mock to return the entity from the start phase final Entity entity = TestEntityGenerator.generateEntity(); //run the stage WriteStart newStage = new WriteStart( logStrategy); //verify the observable is correct CollectionIoEvent<MvccEntity> result = newStage.call( new CollectionIoEvent<Entity>( context, entity ) ); //verify the log entry is correct MvccLogEntry entry = logEntry.getValue(); assertEquals( "id correct", entity.getId(), entry.getEntityId() ); assertEquals( "EventStage is correct", Stage.ACTIVE, entry.getStage() ); MvccEntity created = result.getEvent(); //verify uuid and version in both the MvccEntity and the entity itself //assertSame is used on purpose. We want to make sure the same instance is used, not a copy. //this way the caller's runtime type is retained. assertSame( "id correct", entity.getId(), created.getId() ); assertSame( "Entity correct", entity, created.getEntity().get() ); }
private void givenOldRegionEntry() { when(entryMap.get(eq(key))).thenReturn(null); when(regionEntryFactory.createEntry(any(), any(), any())).thenReturn(factoryRegionEntry); when(entryMap.putIfAbsent(eq(key), same(factoryRegionEntry))).thenReturn(oldRegionEntry); }
@Test public void handleMessageBadData() throws Exception { TextMessage message = new TextMessage("[\"x]"); this.session.handleMessage(message, this.webSocketSession); this.session.isClosed(); verify(this.webSocketHandler).handleTransportError(same(this.session), any(IOException.class)); verifyNoMoreInteractions(this.webSocketHandler); }
@Test public void testStartStage() throws Exception { when( logStrategy.write( same( context ), logEntry.capture() ) ).thenReturn( logMutation ); when( mvccEntityStrategy.write( same( context ), mvccEntityCapture.capture() ) ) .thenReturn( mvccEntityMutation );
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test public void createViewAndController_must_delegate_to_the_proper_ViewBuilder() throws Exception { final ViewBuilder viewBuilder = mock(ViewBuilder.class); final SiteNode siteNode = mock(SiteNode.class); final Id id = new Id("theId"); final ViewAndController viewAndController = mock(ViewAndController.class); when(viewBuilder.createViewAndController(eq(id), same(siteNode))).thenReturn(viewAndController); underTest.viewBuilderMapByTypeUri.put("type1", viewBuilder); final ViewAndController vac = underTest.createViewAndController("type1", id, siteNode); verify(viewBuilder).createViewAndController(eq(id), same(siteNode)); assertThat(vac, is(sameInstance(viewAndController))); }
private void setupTranslationServiceWith(String expectedKey, String desiredResult) { when(translationService.translate(same(localeProvider), eq(new String[]{expectedKey}))).thenReturn(desiredResult); }
@Test public void handleErrorFrameWithConversionException() { StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.ERROR); accessor.setContentType(MimeTypeUtils.APPLICATION_JSON); accessor.addNativeHeader("foo", "bar"); accessor.setLeaveMutable(true); byte[] payload = "{'foo':'bar'}".getBytes(StandardCharsets.UTF_8); StompHeaders stompHeaders = StompHeaders.readOnlyStompHeaders(accessor.getNativeHeaders()); when(this.sessionHandler.getPayloadType(stompHeaders)).thenReturn(Map.class); this.session.handleMessage(MessageBuilder.createMessage(payload, accessor.getMessageHeaders())); verify(this.sessionHandler).getPayloadType(stompHeaders); verify(this.sessionHandler).handleException(same(this.session), same(StompCommand.ERROR), eq(stompHeaders), same(payload), any(MessageConversionException.class)); verifyNoMoreInteractions(this.sessionHandler); }
@Test public void testStartStage() throws Exception { when( logStrategy.write( same( context ), logEntry.capture() ) ).thenReturn( logMutation ); when( mvccEntityStrategy.write( same( context ), mvccEntityCapture.capture() ) ) .thenReturn( mvccEntityMutation );
@Test public void operationsAreCalledInOrder() { final JsonNode node1 = FACTORY.textNode("hello"); final JsonNode node2 = FACTORY.textNode("world"); when(op1.apply(node1)).thenReturn(node2); final JsonPatch patch = new JsonPatch(ImmutableList.of(op1, op2)); final ArgumentCaptor<JsonNode> captor = ArgumentCaptor.forClass(JsonNode.class); patch.apply(node1); verify(op1, only()).apply(same(node1)); verify(op2, only()).apply(captor.capture()); assertSame(captor.getValue(), node2); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test public void must_return_the_interpolated_string_when_metadata_is_found() throws Exception { final Metadata metadata = mock(Metadata.class); when(metadata.interpolateString(anyString(), same(siteNodeProperties))).thenReturn("result"); when(metadataCache.findMetadataById(eq(mediaId), same(siteNodeProperties))).thenReturn(metadata); final String result = underTest.getMetadataString(mediaId, "template", siteNodeProperties); assertThat(result, is("result")); }
@Test public void mapDataSourceWithGetConnectionSuccessClosesConnectionAndRebinds() throws Exception { Map<String, String> inputs = new HashMap<>(); Context context = mock(Context.class); DataSource dataSource = mock(DataSource.class); Connection connection = mock(Connection.class); when(dataSource.getConnection()).thenReturn(connection); DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class); when(dataSourceFactory.getSimpleDataSource(any())).thenReturn(dataSource); inputs.put("type", "SimpleDataSource"); String jndiName = "myJndiBinding"; inputs.put("jndi-name", jndiName); JNDIInvoker.mapDatasource(inputs, null, dataSourceFactory, context); verify(connection).close(); verify(context).rebind((String) any(), same(dataSource)); } }
@Test public void findHost() { org.apache.catalina.Host host = mock(org.apache.catalina.Host.class); HostFactory hostFactory = mock(HostFactory.class); Host expected = mock(Host.class); when(this.engine.findChild("host")).thenReturn(host); when(this.registry.getHostFactory()).thenReturn(hostFactory); when(hostFactory.createHost(same(this.registry), same(host), same(this.catalinaEngine))).thenReturn(expected); Host result = this.catalinaEngine.findHost("host"); assertSame(expected, result); }
@Test public void noFailureDoesNotTriggerEarlyExit() throws ProcessingException { @SuppressWarnings("unchecked") final Processor<MessageProvider, MessageProvider> p1 = mock(Processor.class); @SuppressWarnings("unchecked") final Processor<MessageProvider, MessageProvider> p2 = mock(Processor.class); final Processor<MessageProvider, MessageProvider> processor = ProcessorChain.startWith(p1).failOnError().chainWith(p2) .getProcessor(); final MessageProvider input = mock(MessageProvider.class); final ProcessingReport report = new DummyReport(LogLevel.DEBUG); when(p1.process(report, input)).thenReturn(input); processor.process(report, input); verify(p1).process(same(report), any(MessageProvider.class)); verify(p2).process(same(report), any(MessageProvider.class)); }
@Before public void setup() throws Exception { Mockito.when(serviceLoader.onlyOne(Mockito.same(DeployableContainer.class))).thenReturn(deployableContainer); Mockito.when(deployableContainer.getConfigurationClass()).thenReturn(DummyContainerConfiguration.class); }