@Test public void testAuthenticateLogin_JA() throws Exception { Mockito.when(session.getAttribute(Matchers.eq("loggedInUserId"))).thenReturn(null); Mockito.when(req.getHeader(Matchers.eq("Authorization"))).thenReturn(null); Mockito.when(req.getLocale()).thenReturn(new Locale("ja")); // given filter.init(config); // when filter.doFilter(req, resp, chain); // then Mockito.verify(resp).setStatus(Matchers.eq(401)); Mockito.verify(resp) .setHeader( Matchers.eq("WWW-Authenticate"), Matchers.startsWith("Basic realm=\"Please log in as an organization administrator\"")); }
private void createTestEnvironment() throws Throwable { ZookeeperClientFactory zkFactory = mock(ZookeeperClientFactory.class); sourceEnvironment = new TestEnvironment.Builder() .listeningExecutorService(listeningExecutorService) .apiClientFactory(apiClientFactory) .cloudServerSet(sourceCloudStore.getServerSet()) .hostCount(1) .build(); destinationEnvironment = new TestEnvironment.Builder() .hostCount(1) .apiClientFactory(apiClientFactory) .cloudServerSet(destinationCloudStore.getServerSet()) .httpFileServiceClientFactory(httpFileServiceClientFactory) .zookeeperServersetBuilderFactory(zkFactory) .build(); ZookeeperClient zkBuilder = mock(ZookeeperClient.class); doReturn(zkBuilder).when(zkFactory).create(); doReturn( Collections.singleton( new InetSocketAddress( "127.0.0.1", sourceEnvironment.getHosts()[0].getState().httpPort))) .when(zkBuilder) .getServers(Matchers.startsWith("127.0.0.1:2181"), eq("cloudstore")); ServiceHost sourceHost = sourceEnvironment.getHosts()[0]; startState.sourceLoadBalancerAddress = sourceHost.getPublicUri().toString(); TestHelper.createHostService(sourceCloudStore, Collections.singleton(UsageTag.MGMT.name())); TestHelper.createHostService(sourceCloudStore, Collections.singleton(UsageTag.CLOUD.name())); DeploymentService.State deploymentService = TestHelper.createDeploymentService(destinationCloudStore); startState.destinationDeploymentId = ServiceUtils.getIDFromDocumentSelfLink(deploymentService.documentSelfLink); }
@BeforeMethod public void setUp() throws Exception, DocumentNotFoundException { attachedDiskIds = new ArrayList<>(); attachedDiskEntities = new ArrayList<>(); persistentDiskEntities = new ArrayList<>(); baseDiskEntities = new ArrayList<>(); FlavorEntity vmFlavorEntity = new FlavorEntity(); vmFlavorEntity.setName("vm-100"); vmFlavorEntity.setKind(Vm.KIND); FlavorEntity diskFlavorEntity = new FlavorEntity(); diskFlavorEntity.setName("core-100"); diskFlavorEntity.setKind(PersistentDisk.KIND); task = new TaskEntity(); task.setId("task-1"); vm = new VmEntity(); vm.setName("vm-name-1"); vm.setId(vmId); vm.setFlavorId(vmFlavorEntity.getId()); vm.setState(VmState.STOPPED); disk1 = new PersistentDiskEntity(); disk1.setName(diskName1); disk1.setId(diskId1); disk1.setFlavorId(diskFlavorEntity.getId()); disk1.setCapacityGb(1); persistentDiskEntities.add(disk1); baseDiskEntities.add(disk1); disk2 = new PersistentDiskEntity(); disk2.setName(diskName2); disk2.setId(diskId2); disk2.setFlavorId(diskFlavorEntity.getId()); disk2.setCapacityGb(2); persistentDiskEntities.add(disk2); baseDiskEntities.add(disk2); // String id, String name, String kind, String flavor, String state attachedDisk1 = AttachedDisk.create(disk1.getId(), disk1.getName(), disk1.getKind(), "core-100", 1, false); attachedDisk2 = AttachedDisk.create(disk2.getId(), disk2.getName(), disk2.getKind(), "core-100", 2, false); attachedDiskIds.add(attachedDisk1.getId()); attachedDiskIds.add(attachedDisk2.getId()); attachedDiskEntity1 = new AttachedDiskEntity(); attachedDiskEntity1.setId(attachedDiskId1); attachedDiskEntities.add(attachedDiskEntity1); attachedDiskEntity2 = new AttachedDiskEntity(); attachedDiskEntity2.setId(attachedDiskId2); attachedDiskEntities.add(attachedDiskEntity2); Datastore datastore = new Datastore(); datastore.setId("datastore-id"); when(diskBackend.find(PersistentDisk.KIND, diskId1)).thenReturn(disk1); when(diskBackend.find(PersistentDisk.KIND, diskId2)).thenReturn(disk2); taskCommand = spy( new TaskCommand( xenonClient, photonControllerXenonRestClient, hostClient, housekeeperClient, deployerClient, deployerXenonClient, housekeeperXenonClient, entityLockBackend, task)); when(taskCommand.getHostClient()).thenReturn(hostClient); when(taskCommand.getPhotonControllerXenonRestClient()) .thenReturn(photonControllerXenonRestClient); when(vmBackend.findById(vmId)).thenReturn(vm); when(diskBackend.find(PersistentDisk.KIND, diskId1)).thenReturn(disk1); when(diskBackend.find(PersistentDisk.KIND, diskId2)).thenReturn(disk2); when(attachedDiskBackend.findAttachedDisk(disk1)).thenReturn(attachedDiskEntity1); when(attachedDiskBackend.findAttachedDisk(disk2)).thenReturn(attachedDiskEntity2); when(taskCommand.getHostClient()).thenReturn(hostClient); HostService.State hostServiceState = new HostService.State(); hostServiceState.hostAddress = "host-ip"; when(hostServiceOp.getBody(Matchers.any())).thenReturn(hostServiceState); when(xenonClient.get(Matchers.startsWith(HostServiceFactory.SELF_LINK))) .thenReturn(hostServiceOp); }
@Before public void setUp() throws Exception { // Mocks ServerManagementContext smCtxt = Mockito.mock(ServerManagementContext.class, Mockito.RETURNS_MOCKS); ClientHandshakeAckMessage msg = mock(ClientHandshakeAckMessage.class); final MessageChannelInternal channel = mock(MessageChannelInternal.class); ChannelManager chMgr = mock(ChannelManager.class); ChannelStats stats = mock(ChannelStats.class); final ArgumentCaptor<ChannelID> cidCollector = ArgumentCaptor.forClass(ChannelID.class); when(channel.getChannelID()) .then( new Answer<ChannelID>() { @Override public ChannelID answer(InvocationOnMock invocation) throws Throwable { return cidCollector.getValue(); } }); final ArgumentCaptor<ChannelManagerEventListener> lsnrCaptor = ArgumentCaptor.forClass(ChannelManagerEventListener.class); Mockito.doNothing().when(chMgr).addEventListener(lsnrCaptor.capture()); when(channel.getRemoteAddress()).thenReturn(new TCSocketAddress(8192)); when(channel.createMessage(TCMessageType.CLIENT_HANDSHAKE_ACK_MESSAGE)).thenReturn(msg); when(chMgr.getChannel(cidCollector.capture())).thenReturn(channel); when(msg.getChannel()).thenReturn(channel); channelMgrMbean = new DSOChannelManagerImpl(chMgr, mock(TCConnectionManager.class), "1.0"); Mockito.doAnswer( new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { lsnrCaptor.getValue().channelRemoved(channel); return null; } }) .when(channel) .close(); when(smCtxt.getChannelManager()).thenReturn((DSOChannelManagerMBean) channelMgrMbean); when(stats.getCounter(Matchers.same(channel), Matchers.startsWith("serverMap"))) .thenReturn(mock(SampledCumulativeCounter.class)); when(stats.getCounter( Matchers.same(channel), Matchers.argThat( new ArgumentMatcher<String>() { @Override public boolean matches(Object argument) { // Ugly, ugly, ugly String str = (String) argument; return !str.startsWith("serverMap"); } }))) .thenReturn(SampledCounter.NULL_SAMPLED_COUNTER); when(smCtxt.getChannelStats()).thenReturn(stats); mbeanSvr = mock(MBeanServer.class); dso = new DSO( smCtxt, mock(ServerConfigurationContext.class), mbeanSvr, mock(TerracottaOperatorEventHistoryProvider.class)); }