org.powermock.api.support.membermodification.MemberModifier Java Examples
The following examples show how to use
org.powermock.api.support.membermodification.MemberModifier.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MockEc2ControllerTest.java From aws-mock with MIT License | 6 votes |
@Test public void Test_listInstanceIDs() throws Exception { DefaultMockEc2Instance ec2Mocked1 = new DefaultMockEc2Instance(); ec2Mocked1.setInstanceType(InstanceType.C1_MEDIUM); DefaultMockEc2Instance ec2Mocked2 = new DefaultMockEc2Instance(); ec2Mocked2.setInstanceType(InstanceType.C3_8XLARGE); MockEc2Controller controller = Mockito.spy(MockEc2Controller.class); Map<String, AbstractMockEc2Instance> allMockEc2Instances = new ConcurrentHashMap<String, AbstractMockEc2Instance>(); allMockEc2Instances.put("ec2Mocked1", ec2Mocked1); allMockEc2Instances.put("ec2Mocked2", ec2Mocked2); MemberModifier.field(MockEc2Controller.class, "allMockEc2Instances").set(controller, allMockEc2Instances); Set<String> instanceIDs = new TreeSet<String>(); instanceIDs.add("ec2Mocked1"); Assert.assertTrue(controller.listInstanceIDs(instanceIDs).get(0).equals("ec2Mocked1")); }
Example #2
Source File: DataCarrierTest.java From DataCarrier with Apache License 2.0 | 6 votes |
@Test public void testCreateDataCarrier() throws IllegalAccessException { DataCarrier<SampleData> carrier = new DataCarrier<SampleData>(5, 100); Assert.assertEquals(((Integer) (MemberModifier.field(DataCarrier.class, "bufferSize").get(carrier))).intValue(), 100); Assert.assertEquals(((Integer) (MemberModifier.field(DataCarrier.class, "channelSize").get(carrier))).intValue(), 5); Channels<SampleData> channels = (Channels<SampleData>) (MemberModifier.field(DataCarrier.class, "channels").get(carrier)); Assert.assertEquals(channels.getChannelSize(), 5); Buffer<SampleData> buffer = channels.getBuffer(0); Assert.assertEquals(buffer.getBufferSize(), 100); Assert.assertEquals(MemberModifier.field(Buffer.class, "strategy").get(buffer), BufferStrategy.BLOCKING); carrier.setBufferStrategy(BufferStrategy.IF_POSSIBLE); Assert.assertEquals(MemberModifier.field(Buffer.class, "strategy").get(buffer), BufferStrategy.IF_POSSIBLE); Assert.assertEquals(MemberModifier.field(Channels.class, "dataPartitioner").get(channels).getClass(), SimpleRollingPartitioner.class); carrier.setPartitioner(new ProducerThreadPartitioner<SampleData>()); Assert.assertEquals(MemberModifier.field(Channels.class, "dataPartitioner").get(channels).getClass(), ProducerThreadPartitioner.class); }
Example #3
Source File: DataCarrierTest.java From DataCarrier with Apache License 2.0 | 6 votes |
@Test public void testProduce() throws IllegalAccessException { DataCarrier<SampleData> carrier = new DataCarrier<SampleData>(2, 100); Assert.assertTrue(carrier.produce(new SampleData().setName("a"))); Assert.assertTrue(carrier.produce(new SampleData().setName("b"))); Assert.assertTrue(carrier.produce(new SampleData().setName("c"))); Assert.assertTrue(carrier.produce(new SampleData().setName("d"))); Channels<SampleData> channels = (Channels<SampleData>) (MemberModifier.field(DataCarrier.class, "channels").get(carrier)); Buffer<SampleData> buffer1 = channels.getBuffer(0); List result1 = buffer1.obtain(0, 100); Buffer<SampleData> buffer2 = channels.getBuffer(1); List result2 = buffer2.obtain(0, 100); Assert.assertEquals(2, result1.size()); Assert.assertEquals(4, result1.size() + result2.size()); }
Example #4
Source File: DataCarrierTest.java From DataCarrier with Apache License 2.0 | 6 votes |
@Test public void testOverrideProduce() throws IllegalAccessException { DataCarrier<SampleData> carrier = new DataCarrier<SampleData>(2, 100); carrier.setBufferStrategy(BufferStrategy.OVERRIDE); for (int i = 0; i < 500; i++) { Assert.assertTrue(carrier.produce(new SampleData().setName("d" + i))); } Channels<SampleData> channels = (Channels<SampleData>) (MemberModifier.field(DataCarrier.class, "channels").get(carrier)); Buffer<SampleData> buffer1 = channels.getBuffer(0); List result1 = buffer1.obtain(0, 100); Buffer<SampleData> buffer2 = channels.getBuffer(1); List result2 = buffer2.obtain(0, 100); Assert.assertEquals(200, result1.size() + result2.size()); }
Example #5
Source File: DataCarrierTest.java From DataCarrier with Apache License 2.0 | 6 votes |
@Test public void testIfPossibleProduce() throws IllegalAccessException { DataCarrier<SampleData> carrier = new DataCarrier<SampleData>(2, 100); carrier.setBufferStrategy(BufferStrategy.IF_POSSIBLE); for (int i = 0; i < 200; i++) { Assert.assertTrue(carrier.produce(new SampleData().setName("d" + i))); } for (int i = 0; i < 200; i++) { Assert.assertFalse(carrier.produce(new SampleData().setName("d" + i + "_2"))); } Channels<SampleData> channels = (Channels<SampleData>) (MemberModifier.field(DataCarrier.class, "channels").get(carrier)); Buffer<SampleData> buffer1 = channels.getBuffer(0); List result1 = buffer1.obtain(0, 100); Buffer<SampleData> buffer2 = channels.getBuffer(1); List result2 = buffer2.obtain(0, 100); Assert.assertEquals(200, result1.size() + result2.size()); }
Example #6
Source File: MockVpcControllerTest.java From aws-mock with MIT License | 6 votes |
@Test public void Test_describeVpc() throws Exception { MockVpcController controller = Mockito.spy(MockVpcController.class); Map<String, MockVpc> allMockVpc = new ConcurrentHashMap<String, MockVpc>(); MockVpc mockVpc = new MockVpc(); allMockVpc.put("i-2323", mockVpc); MockVpc mockVpc1 = new MockVpc(); allMockVpc.put("i-23223233", mockVpc1); MemberModifier.field(MockVpcController.class, "allMockVpcInstances").set(controller, allMockVpc); Collection<MockVpc> collectionOfMockVpc = controller.describeVpcs(); int collectionCount = collectionOfMockVpc.size(); // Returns collection of size 2 Assert.assertEquals(2, collectionCount); }
Example #7
Source File: AwesomeValidationTest.java From AwesomeValidation with MIT License | 6 votes |
@Override protected void setUp() throws Exception { super.setUp(); mSpiedBasicValidator = spy(BasicValidator.class); mSpiedColorationValidator = spy(ColorationValidator.class); mSpiedUnderlabelValidator = spy(UnderlabelValidator.class); mSpiedTextInputLayoutValidator = spy(TextInputLayoutValidator.class); mSpiedAwesomeValidationBasicStyle = spy(new AwesomeValidation(ValidationStyle.BASIC)); mSpiedAwesomeValidationColorationStyle = spy(new AwesomeValidation(ValidationStyle.COLORATION)); mSpiedAwesomeValidationUnderlabelStyle = spy(new AwesomeValidation(ValidationStyle.UNDERLABEL)); mSpiedAwesomeValidationTextInputLayoutStyle = spy(new AwesomeValidation(ValidationStyle.TEXT_INPUT_LAYOUT)); MemberModifier.field(AwesomeValidation.class, "mValidator").set(mSpiedAwesomeValidationBasicStyle, mSpiedBasicValidator); MemberModifier.field(AwesomeValidation.class, "mValidator").set(mSpiedAwesomeValidationColorationStyle, mSpiedColorationValidator); MemberModifier.field(AwesomeValidation.class, "mValidator").set(mSpiedAwesomeValidationUnderlabelStyle, mSpiedUnderlabelValidator); MemberModifier.field(AwesomeValidation.class, "mValidator").set(mSpiedAwesomeValidationTextInputLayoutStyle, mSpiedTextInputLayoutValidator); mMockContext = mock(Context.class); }
Example #8
Source File: FsSourceTaskTest.java From kafka-connect-fs with Apache License 2.0 | 6 votes |
@ParameterizedTest @MethodSource("fileSystemConfigProvider") public void exceptionExecutingPolicy(TaskFsTestConfig fsConfig) throws IOException, IllegalAccessException { Map<String, String> props = new HashMap<>(fsConfig.getTaskConfig()); fsConfig.getTask().start(props); Policy policy = EasyMock.createNiceMock(Policy.class); EasyMock.expect(policy.hasEnded()).andReturn(Boolean.FALSE); EasyMock.expect(policy.execute()).andThrow(new ConnectException("Exception from mock")); EasyMock.expect(policy.getURIs()).andReturn(null); EasyMock.checkOrder(policy, false); EasyMock.replay(policy); MemberModifier.field(FsSourceTask.class, "policy").set(fsConfig.getTask(), policy); assertEquals(0, fsConfig.getTask().poll().size()); }
Example #9
Source File: ShibcasAuthServletTest.java From shib-cas-authn3 with Apache License 2.0 | 6 votes |
@Test public void testDoGetBadTicket() throws Exception { //Mock some objects. final HttpServletRequest request = createDoGetHttpServletRequest(CONVERSATION_TICKET, TICKET, "false"); final HttpServletResponse response = createMockHttpServletResponse(); final Cas20ServiceTicketValidator ticketValidator = PowerMockito.mock(Cas20ServiceTicketValidator.class); PowerMockito.when(ticketValidator.validate(TICKET, URL_WITH_CONVERSATION)).thenThrow(new TicketValidationException("Invalid Ticket")); PowerMockito.mockStatic(ExternalAuthentication.class); BDDMockito.given(ExternalAuthentication.startExternalAuthentication(request)).willThrow(new ExternalAuthenticationException()); //Prep our object final ShibcasAuthServlet shibcasAuthServlet = createShibcasAuthServlet(); //Override the internal Cas20TicketValidator because we don't want it to call a real server MemberModifier.field(ShibcasAuthServlet.class, "ticketValidator").set(shibcasAuthServlet, ticketValidator); //Standard request/response - bad ticket BDDMockito.given(request.getAttribute(ExternalAuthentication.FORCE_AUTHN_PARAM)).willReturn("false"); BDDMockito.given(request.getAttribute(ExternalAuthentication.PASSIVE_AUTHN_PARAM)).willReturn("false"); shibcasAuthServlet.doGet(request, response); //Verify verify(request).getRequestDispatcher("/no-conversation-state.jsp"); verify(response).setStatus(404); }
Example #10
Source File: OvsdbBridgeUpdateCommandTest.java From ovsdb with Eclipse Public License 1.0 | 6 votes |
@Test public void testExecute() throws Exception { updatedBridgeRows.put(mock(UUID.class), mock(Bridge.class)); OvsdbConnectionInstance ovsdbConnectionInstance = mock(OvsdbConnectionInstance.class); when(ovsdbBridgeUpdateCommand.getOvsdbConnectionInstance()).thenReturn(ovsdbConnectionInstance); InstanceIdentifier<Node> connectionIId = mock(InstanceIdentifier.class); when(ovsdbConnectionInstance.getInstanceIdentifier()).thenReturn(connectionIId); Optional<Node> connection = Optional.of(mock(Node.class)); PowerMockito.mockStatic(SouthboundUtil.class); when(SouthboundUtil.readNode(any(ReadWriteTransaction.class), any(InstanceIdentifier.class))) .thenReturn(connection); ReadWriteTransaction transaction = mock(ReadWriteTransaction.class); MemberModifier.suppress(MemberMatcher.method(OvsdbBridgeUpdateCommand.class, "updateBridge", ReadWriteTransaction.class, Bridge.class, InstanceIdentifier.class)); ovsdbBridgeUpdateCommand.execute(transaction); verify(ovsdbBridgeUpdateCommand).updateBridge(any(ReadWriteTransaction.class), any(Bridge.class), any(InstanceIdentifier.class)); }
Example #11
Source File: OvsdbBridgeRemovedCommandTest.java From ovsdb with Eclipse Public License 1.0 | 6 votes |
@Test public void testExecute() throws Exception { //suppress calls to parent get methods MemberModifier.suppress(MemberMatcher.method(OvsdbBridgeRemovedCommand.class, "getUpdates")); when(ovsdbBridgeRemovedCommand.getUpdates()).thenReturn(mock(TableUpdates.class)); MemberModifier.suppress(MemberMatcher.method(OvsdbBridgeRemovedCommand.class, "getDbSchema")); when(ovsdbBridgeRemovedCommand.getDbSchema()).thenReturn(mock(DatabaseSchema.class)); PowerMockito.mockStatic(TyperUtils.class); Map<UUID, Bridge> map = new HashMap<>(); when(TyperUtils.extractRowsRemoved(eq(Bridge.class), any(TableUpdates.class), any(DatabaseSchema.class))) .thenReturn(map); ReadWriteTransaction transaction = mock(ReadWriteTransaction.class); ovsdbBridgeRemovedCommand.execute(transaction); verify(ovsdbBridgeRemovedCommand).getUpdates(); verify(ovsdbBridgeRemovedCommand).getDbSchema(); }
Example #12
Source File: DataCarrierTest.java From skywalking with Apache License 2.0 | 6 votes |
@Test public void testIfPossibleProduce() throws IllegalAccessException { DataCarrier<SampleData> carrier = new DataCarrier<SampleData>(2, 100); carrier.setBufferStrategy(BufferStrategy.IF_POSSIBLE); for (int i = 0; i < 200; i++) { Assert.assertTrue(carrier.produce(new SampleData().setName("d" + i))); } for (int i = 0; i < 200; i++) { Assert.assertFalse(carrier.produce(new SampleData().setName("d" + i + "_2"))); } Channels<SampleData> channels = (Channels<SampleData>) (MemberModifier.field(DataCarrier.class, "channels") .get(carrier)); QueueBuffer<SampleData> buffer1 = channels.getBuffer(0); List result = new ArrayList(); buffer1.obtain(result); QueueBuffer<SampleData> buffer2 = channels.getBuffer(1); buffer2.obtain(result); Assert.assertEquals(200, result.size()); }
Example #13
Source File: MockVolumeControllerTest.java From aws-mock with MIT License | 6 votes |
@Test public void Test_describeVolume() throws Exception { MockVolumeController controller = Mockito.spy(MockVolumeController.class); Map<String, MockVolume> allMockVolume = new ConcurrentHashMap<String, MockVolume>(); MockVolume mockVolume = new MockVolume(); allMockVolume.put("i-2323", mockVolume); MockVolume mockVolume1 = new MockVolume(); allMockVolume.put("i-23223233", mockVolume1); MemberModifier.field(MockVolumeController.class, "allMockVolumes").set(controller, allMockVolume); Collection<MockVolume> collectionOfMockVolume = controller.describeVolumes(); int collectionCount = collectionOfMockVolume.size(); // Returns collection of size 2 Assert.assertEquals(2, collectionCount); }
Example #14
Source File: OvsdbConnectionManagerTest.java From ovsdb with Eclipse Public License 1.0 | 6 votes |
@Test public void testPutAndGetConnectionInstance() throws Exception { ConnectionInfo key = mock(ConnectionInfo.class); ConnectionInfo connectionInfo = mock(ConnectionInfo.class); PowerMockito.mockStatic(SouthboundMapper.class); when(SouthboundMapper.suppressLocalIpPort(key)).thenReturn(connectionInfo); clients = new ConcurrentHashMap<>(); MemberModifier.field(OvsdbConnectionManager.class, "clients").set(ovsdbConnManager, clients); // Test putConnectionInstance() OvsdbConnectionInstance instance = mock(OvsdbConnectionInstance.class); Whitebox.invokeMethod(ovsdbConnManager, "putConnectionInstance", key, instance); Map<ConnectionInfo, OvsdbConnectionInstance> testClients = Whitebox.getInternalState(ovsdbConnManager, "clients"); assertEquals("Error, size of the hashmap is incorrect", 1, testClients.size()); // Test getConnectionInstance(ConnectionInfo key) assertEquals("Error, returned incorrect OvsdbConnectionInstance object", instance, ovsdbConnManager.getConnectionInstance(key)); }
Example #15
Source File: MockEc2ControllerTest.java From aws-mock with MIT License | 6 votes |
@Test public void Test_getMockEc2Instance() throws Exception { DefaultMockEc2Instance ec2Mocked1 = new DefaultMockEc2Instance(); ec2Mocked1.setInstanceType(InstanceType.C1_MEDIUM); DefaultMockEc2Instance ec2Mocked2 = new DefaultMockEc2Instance(); ec2Mocked2.setInstanceType(InstanceType.C3_8XLARGE); MockEc2Controller controller = Mockito.spy(MockEc2Controller.class); Map<String, AbstractMockEc2Instance> allMockEc2Instances = new ConcurrentHashMap<String, AbstractMockEc2Instance>(); allMockEc2Instances.put("ec2Mocked1", ec2Mocked1); allMockEc2Instances.put("ec2Mocked2", ec2Mocked2); MemberModifier.field(MockEc2Controller.class, "allMockEc2Instances").set(controller, allMockEc2Instances); Assert.assertTrue(controller.getMockEc2Instance("ec2Mocked1") == ec2Mocked1); Assert.assertTrue(controller.getMockEc2Instance("ec2Mocked2") == ec2Mocked2); }
Example #16
Source File: MockEc2ControllerTest.java From aws-mock with MIT License | 6 votes |
@Test public void Test_getAllMockEc2Instances() throws Exception { DefaultMockEc2Instance ec2Mocked1 = new DefaultMockEc2Instance(); ec2Mocked1.setInstanceType(InstanceType.C1_MEDIUM); DefaultMockEc2Instance ec2Mocked2 = new DefaultMockEc2Instance(); ec2Mocked2.setInstanceType(InstanceType.C3_8XLARGE); MockEc2Controller controller = Mockito.spy(MockEc2Controller.class); Map<String, AbstractMockEc2Instance> allMockEc2Instances = new ConcurrentHashMap<String, AbstractMockEc2Instance>(); allMockEc2Instances.put("ec2Mocked1", ec2Mocked1); allMockEc2Instances.put("ec2Mocked2", ec2Mocked2); MemberModifier.field(MockEc2Controller.class, "allMockEc2Instances").set(controller, allMockEc2Instances); Collection<AbstractMockEc2Instance> collectionOfEc2Instances = controller .getAllMockEc2Instances(); Assert.assertTrue(collectionOfEc2Instances.size() == 2); Assert.assertTrue(collectionOfEc2Instances.contains(ec2Mocked1)); Assert.assertTrue(collectionOfEc2Instances.contains(ec2Mocked2)); }
Example #17
Source File: OvsdbManagersRemovedCommandTest.java From ovsdb with Eclipse Public License 1.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void testExecute() throws Exception { updatedOpenVSwitchRows = new HashMap<>(); UUID uuid = mock(UUID.class); OpenVSwitch openVSwitch = mock(OpenVSwitch.class); updatedOpenVSwitchRows.put(uuid, openVSwitch); MemberModifier.field(OvsdbManagersRemovedCommand.class, "updatedOpenVSwitchRows") .set(ovsdbManagersRemovedCommand, updatedOpenVSwitchRows); PowerMockito.mockStatic(SouthboundMapper.class); OvsdbConnectionInstance ovsdbConnectionInstance = mock(OvsdbConnectionInstance.class); when(ovsdbManagersRemovedCommand.getOvsdbConnectionInstance()).thenReturn(ovsdbConnectionInstance); when(ovsdbConnectionInstance.getNodeId()).thenReturn(mock(NodeId.class)); when(SouthboundMapper.createInstanceIdentifier(any(NodeId.class))).thenReturn(mock(InstanceIdentifier.class)); doNothing().when(ovsdbManagersRemovedCommand).deleteManagers(any(ReadWriteTransaction.class), any(List.class)); doReturn(mock(List.class)).when(ovsdbManagersRemovedCommand).managerEntriesToRemove( any(InstanceIdentifier.class), any(OpenVSwitch.class)); ReadWriteTransaction transaction = mock(ReadWriteTransaction.class); ovsdbManagersRemovedCommand.execute(transaction); verify(ovsdbManagersRemovedCommand).deleteManagers(any(ReadWriteTransaction.class), any(List.class)); verify(ovsdbManagersRemovedCommand).managerEntriesToRemove(any(InstanceIdentifier.class), any(OpenVSwitch.class)); }
Example #18
Source File: OvsdbManagersRemovedCommandTest.java From ovsdb with Eclipse Public License 1.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void testCheckIfManagerPresentInUpdatedManagersList() throws Exception { Manager updatedManager = mock(Manager.class); updatedManagerRows = new HashMap<>(); UUID uuid = mock(UUID.class); updatedManagerRows.put(uuid, updatedManager); MemberModifier.field(OvsdbManagersRemovedCommand.class, "updatedManagerRows").set(ovsdbManagersRemovedCommand, updatedManagerRows); Column<GenericTableSchema, String> column = mock(Column.class); Manager removedManager = mock(Manager.class); when(removedManager.getTargetColumn()).thenReturn(column); when(updatedManager.getTargetColumn()).thenReturn(column); when(column.getData()).thenReturn(TARGET_COLUMN_DATA); assertEquals(true, Whitebox.invokeMethod(ovsdbManagersRemovedCommand, "checkIfManagerPresentInUpdatedManagersList", removedManager)); }
Example #19
Source File: ShibcasAuthServletTest.java From shib-cas-authn3 with Apache License 2.0 | 6 votes |
@Test public void testDoGetBadTicket() throws Exception { //Mock some objects. final HttpServletRequest request = createDoGetHttpServletRequest(CONVERSATION_TICKET, TICKET, "false"); final HttpServletResponse response = createMockHttpServletResponse(); final Cas20ServiceTicketValidator ticketValidator = PowerMockito.mock(Cas20ServiceTicketValidator.class); PowerMockito.when(ticketValidator.validate(TICKET, URL_WITH_CONVERSATION)).thenThrow(new TicketValidationException("Invalid Ticket")); PowerMockito.mockStatic(ExternalAuthentication.class); BDDMockito.given(ExternalAuthentication.startExternalAuthentication(request)).willThrow(new ExternalAuthenticationException()); //Prep our object final ShibcasAuthServlet shibcasAuthServlet = createShibcasAuthServlet(); //Override the internal Cas20TicketValidator because we don't want it to call a real server MemberModifier.field(ShibcasAuthServlet.class, "ticketValidator").set(shibcasAuthServlet, ticketValidator); //Standard request/response - bad ticket BDDMockito.given(request.getAttribute(ExternalAuthentication.FORCE_AUTHN_PARAM)).willReturn("false"); BDDMockito.given(request.getAttribute(ExternalAuthentication.PASSIVE_AUTHN_PARAM)).willReturn("false"); shibcasAuthServlet.doGet(request, response); //Verify verify(request).getRequestDispatcher("/no-conversation-state.jsp"); verify(response).setStatus(404); }
Example #20
Source File: OvsdbManagersUpdateCommandTest.java From ovsdb with Eclipse Public License 1.0 | 6 votes |
@Test public void testExecute() throws Exception { Map<UUID, Manager> updatedManagerRows = new HashMap<>(); updatedManagerRows.put(mock(UUID.class), mock(Manager.class)); MemberModifier.field(OvsdbManagersUpdateCommand.class, "updatedManagerRows").set(ovsdbManagersUpdateCommand, updatedManagerRows); Map<Uri, Manager> updatedManagerRowsWithUri = new HashMap<>(); PowerMockito.doReturn(updatedManagerRowsWithUri).when(ovsdbManagersUpdateCommand, "getUriManagerMap", any(Map.class)); Map<UUID, OpenVSwitch> updatedOpenVSwitchRows = new HashMap<>(); updatedOpenVSwitchRows.put(mock(UUID.class), mock(OpenVSwitch.class)); MemberModifier.field(OvsdbManagersUpdateCommand.class, "updatedOpenVSwitchRows").set(ovsdbManagersUpdateCommand, updatedOpenVSwitchRows); // mock updateManagers() PowerMockito.doNothing().when(ovsdbManagersUpdateCommand, "updateManagers", any(ReadWriteTransaction.class), any(Map.class), any(Map.class)); ReadWriteTransaction transaction = mock(ReadWriteTransaction.class); ovsdbManagersUpdateCommand.execute(transaction); PowerMockito.verifyPrivate(ovsdbManagersUpdateCommand).invoke("getUriManagerMap", any(Map.class)); PowerMockito.verifyPrivate(ovsdbManagersUpdateCommand).invoke("updateManagers", any(ReadWriteTransaction.class), any(Map.class), any(Map.class)); }
Example #21
Source File: OvsdbControllerUpdateCommandTest.java From ovsdb with Eclipse Public License 1.0 | 6 votes |
@Test public void testExecute() throws Exception { Map<UUID, Controller> updatedControllerRows = new HashMap<>(); updatedControllerRows.put(mock(UUID.class), mock(Controller.class)); MemberModifier.field(OvsdbControllerUpdateCommand.class, "updatedControllerRows") .set(ovsdbControllerUpdateCommand, updatedControllerRows); MemberModifier.suppress(MemberMatcher.method(OvsdbControllerUpdateCommand.class, "updateController", ReadWriteTransaction.class, Map.class, Map.class)); MemberModifier.suppress(MemberMatcher.method(OvsdbControllerUpdateCommand.class, "updateController", ReadWriteTransaction.class, Map.class)); // updatedBridgeRows null case ReadWriteTransaction transaction = mock(ReadWriteTransaction.class); ovsdbControllerUpdateCommand.execute(transaction); verify(ovsdbControllerUpdateCommand).updateController(any(ReadWriteTransaction.class), any(Map.class)); // updatedBridgeRows not null case Map<UUID, Bridge> updatedBridgeRows = new HashMap<>(); updatedBridgeRows.put(mock(UUID.class), mock(Bridge.class)); MemberModifier.field(OvsdbControllerUpdateCommand.class, "updatedBridgeRows").set(ovsdbControllerUpdateCommand, updatedBridgeRows); }
Example #22
Source File: DataCarrierTest.java From skywalking with Apache License 2.0 | 6 votes |
@Test public void testProduce() throws IllegalAccessException { DataCarrier<SampleData> carrier = new DataCarrier<SampleData>(2, 100); Assert.assertTrue(carrier.produce(new SampleData().setName("a"))); Assert.assertTrue(carrier.produce(new SampleData().setName("b"))); Assert.assertTrue(carrier.produce(new SampleData().setName("c"))); Assert.assertTrue(carrier.produce(new SampleData().setName("d"))); Channels<SampleData> channels = (Channels<SampleData>) (MemberModifier.field(DataCarrier.class, "channels") .get(carrier)); QueueBuffer<SampleData> buffer1 = channels.getBuffer(0); List result = new ArrayList(); buffer1.obtain(result); Assert.assertEquals(2, result.size()); QueueBuffer<SampleData> buffer2 = channels.getBuffer(1); buffer2.obtain(result); Assert.assertEquals(4, result.size()); }
Example #23
Source File: MockVpcControllerTest.java From aws-mock with MIT License | 5 votes |
@Test public void Test_restoreAllVpc() throws Exception { MockVpcController controller = Mockito.spy(MockVpcController.class); Map<String, MockVpc> allMockVpc = new ConcurrentHashMap<String, MockVpc>(); MockVpc mockVpc = new MockVpc(); mockVpc.setVpcId("vpc-asdasd"); allMockVpc.put("i-2323", mockVpc); MockVpc mockVpc1 = new MockVpc(); mockVpc1.setVpcId("vpc-awewewewe"); allMockVpc.put("i-23223233", mockVpc1); MemberModifier.field(MockVpcController.class, "allMockVpcInstances").set(controller, allMockVpc); Collection<MockVpc> collectionOfMockVpc = controller.describeVpcs(); Collection<MockVpc> restoreVpcs = new ArrayList<MockVpc>(collectionOfMockVpc.size()); for (MockVpc mockVpcRes : collectionOfMockVpc) { restoreVpcs.add(mockVpcRes); } int collectionCount = collectionOfMockVpc.size(); // Returns collection of size 2 Assert.assertEquals(2, collectionCount); for(MockVpc restoreVpc : collectionOfMockVpc) { controller.deleteVpc(restoreVpc.getVpcId()); } controller.restoreAllMockVpc(restoreVpcs); collectionOfMockVpc = controller.describeVpcs(); collectionCount = collectionOfMockVpc.size(); // Returns collection of size 2 Assert.assertEquals(2, collectionCount); }
Example #24
Source File: ShibcasAuthServletTest.java From shib-cas-authn3 with Apache License 2.0 | 5 votes |
@Test public void testDoGetPassiveAndForced() throws Exception { //Mock some objects. final HttpServletRequest request = createDoGetHttpServletRequest(CONVERSATION_TICKET_GATEWAY_ATTEMPTED, TICKET, "true"); final HttpServletResponse response = createMockHttpServletResponse(); final Assertion assertion = createMockAssertion(); final Cas20ServiceTicketValidator ticketValidator = PowerMockito.mock(Cas30ServiceTicketValidator.class); PowerMockito.when(ticketValidator.validate(TICKET, URL_WITH_CONVERSATION_GATEWAY_ATTEMPTED)).thenReturn(assertion); PowerMockito.mockStatic(ExternalAuthentication.class); BDDMockito.given(ExternalAuthentication.startExternalAuthentication(request)).willReturn(E1S1); //Prep our object final ShibcasAuthServlet shibcasAuthServlet = createShibcasAuthServlet(); //Override the internal Cas30TicketValidator because we don't want it to call a real server MemberModifier.field(ShibcasAuthServlet.class, "ticketValidator").set(shibcasAuthServlet, ticketValidator); //Passive and forced request/response BDDMockito.given(request.getAttribute(ExternalAuthentication.FORCE_AUTHN_PARAM)).willReturn("true"); BDDMockito.given(request.getAttribute(ExternalAuthentication.PASSIVE_AUTHN_PARAM)).willReturn("true"); shibcasAuthServlet.doGet(request, response); //Verify verify(request).setAttribute(ExternalAuthentication.PRINCIPAL_NAME_KEY, JDOE); }
Example #25
Source File: MockEc2ControllerTest.java From aws-mock with MIT License | 5 votes |
@Test public void Test_describeInstances() throws Exception { DefaultMockEc2Instance ec2Mocked1 = new DefaultMockEc2Instance(); ec2Mocked1.setInstanceType(InstanceType.C1_MEDIUM); DefaultMockEc2Instance ec2Mocked2 = new DefaultMockEc2Instance(); ec2Mocked2.setInstanceType(InstanceType.C3_8XLARGE); Set<String> instanceIDs = new HashSet<String>(); instanceIDs.add(ec2Mocked1.getInstanceID()); // we will search for only the first instance MockEc2Controller controller = Mockito.spy(MockEc2Controller.class); Map<String, AbstractMockEc2Instance> allMockEc2Instances = new ConcurrentHashMap<String, AbstractMockEc2Instance>(); allMockEc2Instances.put(ec2Mocked1.getInstanceID(), ec2Mocked1); allMockEc2Instances.put(ec2Mocked2.getInstanceID(), ec2Mocked2); MemberModifier.field(MockEc2Controller.class, "allMockEc2Instances").set(controller, allMockEc2Instances); Collection<AbstractMockEc2Instance> collectionOfMockedInstances = controller .describeInstances(instanceIDs); Assert.assertTrue(collectionOfMockedInstances.size() == 1); for (AbstractMockEc2Instance instance : collectionOfMockedInstances) { Assert.assertTrue(instance == ec2Mocked1); } }
Example #26
Source File: ShellPrevalidatorTest.java From pentaho-hadoop-shims with Apache License 2.0 | 5 votes |
@Test public void validateReturnTrueIfNotWindows() throws IOException { MemberModifier .stub( MemberModifier.method( ShellPrevalidator.class, "isWindows" ) ) .toReturn( false ); MemberModifier .stub( MemberModifier.method( ShellPrevalidator.class, "doesFileExist", String.class ) ) .toReturn( false ); boolean exist = ShellPrevalidator.doesWinutilsFileExist(); Assert.assertEquals( true, exist ); }
Example #27
Source File: ShellPrevalidatorTest.java From pentaho-hadoop-shims with Apache License 2.0 | 5 votes |
@Test( expected = IOException.class ) public void validateThrowExceptionWhenWindowsAndFileNotExist() throws IOException { MemberModifier .stub( MemberModifier.method( ShellPrevalidator.class, "isWindows" ) ) .toReturn( true ); MemberModifier .stub( MemberModifier.method( ShellPrevalidator.class, "doesFileExist", String.class ) ) .toReturn( false ); boolean exist = ShellPrevalidator.doesWinutilsFileExist(); Assert.assertEquals( false, exist ); }
Example #28
Source File: OvsdbConnectionManagerTest.java From ovsdb with Eclipse Public License 1.0 | 5 votes |
@Test public void testClose() throws Exception { ConnectionInfo key1 = mock(ConnectionInfo.class); ConnectionInfo key2 = mock(ConnectionInfo.class); OvsdbConnectionInstance ovsdbConnectionInstance1 = mock(OvsdbConnectionInstance.class); OvsdbConnectionInstance ovsdbConnectionInstance2 = mock(OvsdbConnectionInstance.class); clients = new ConcurrentHashMap<>(); clients.put(key1, ovsdbConnectionInstance1); clients.put(key2, ovsdbConnectionInstance2); MemberModifier.field(OvsdbConnectionManager.class, "clients").set(ovsdbConnManager, clients); ovsdbConnManager.close(); verify(ovsdbConnectionInstance1).disconnect(); verify(ovsdbConnectionInstance2).disconnect(); }
Example #29
Source File: MockVolumeControllerTest.java From aws-mock with MIT License | 5 votes |
@Test public void Test_describeVolumeRestore() throws Exception { MockVolumeController controller = Mockito.spy(MockVolumeController.class); Map<String, MockVolume> allMockVolume = new ConcurrentHashMap<String, MockVolume>(); MockVolume mockVolume = new MockVolume(); mockVolume.setVolumeId("vol-21212"); allMockVolume.put("i-2323", mockVolume); MockVolume mockVolume1 = new MockVolume(); mockVolume1.setVolumeId("vol-21212wewe"); allMockVolume.put("i-23223233", mockVolume1); MemberModifier.field(MockVolumeController.class, "allMockVolumes").set(controller, allMockVolume); Collection<MockVolume> collectionOfMockVolume = controller.describeVolumes(); Collection<MockVolume> restoreVolumes = new ArrayList<MockVolume>(collectionOfMockVolume.size()); for (MockVolume mockVol : collectionOfMockVolume) { restoreVolumes.add(mockVol); } // Returns collection of size 2 Assert.assertEquals(2, collectionOfMockVolume.size()); for (MockVolume mockRestoreVol : collectionOfMockVolume) { controller.deleteVolume(mockRestoreVol.getVolumeId()); } controller.restoreAllMockVolume(restoreVolumes); collectionOfMockVolume = controller.describeVolumes(); // Returns collection of size 2 Assert.assertEquals(2, collectionOfMockVolume.size()); }
Example #30
Source File: OvsdbBridgeUpdateCommandTest.java From ovsdb with Eclipse Public License 1.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testUpdateBridge() throws Exception { MemberModifier .suppress(MemberMatcher.method(OvsdbBridgeUpdateCommand.class, "buildConnectionNode", Bridge.class)); ReadWriteTransaction transaction = mock(ReadWriteTransaction.class); doNothing().when(transaction).merge(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class)); // suppress calls to private methods MemberModifier .suppress(MemberMatcher.method(OvsdbBridgeUpdateCommand.class, "getInstanceIdentifier", Bridge.class)); MemberModifier.suppress(MemberMatcher.method(OvsdbBridgeUpdateCommand.class, "buildBridgeNode", Bridge.class)); MemberModifier.suppress(MemberMatcher.method(OvsdbBridgeUpdateCommand.class, "deleteEntries", ReadWriteTransaction.class, List.class)); MemberModifier.suppress(MemberMatcher.method(OvsdbBridgeUpdateCommand.class, "protocolEntriesToRemove", InstanceIdentifier.class, Bridge.class)); MemberModifier.suppress(MemberMatcher.method(OvsdbBridgeUpdateCommand.class, "externalIdsToRemove", InstanceIdentifier.class, Bridge.class)); MemberModifier.suppress(MemberMatcher.method(OvsdbBridgeUpdateCommand.class, "bridgeOtherConfigsToRemove", InstanceIdentifier.class, Bridge.class)); MemberModifier.suppress(MemberMatcher.method(OvsdbBridgeUpdateCommand.class, "getNodeId", Bridge.class)); Bridge bridge = mock(Bridge.class); InstanceIdentifier<Node> connectionIId = mock(InstanceIdentifier.class); Whitebox.invokeMethod(ovsdbBridgeUpdateCommand, "updateBridge", transaction, bridge, connectionIId); verify(ovsdbBridgeUpdateCommand, times(3)).deleteEntries(any(ReadWriteTransaction.class), eq(null)); }