How to use InstanceOf class of org.easymock.internal.matchers package

Best Easymock code snippet using org.easymock.internal.matchers.InstanceOf

Source:OFSwitchHandshakeHandlerVer13Test.java Github

copy

Full Screen

1package net.floodlightcontroller.core.internal;2import static org.easymock.EasyMock.anyObject;3import static org.easymock.EasyMock.eq;4import static org.easymock.EasyMock.expect;5import static org.easymock.EasyMock.expectLastCall;6import static org.easymock.EasyMock.replay;7import static org.easymock.EasyMock.reset;8import static org.easymock.EasyMock.verify;9import static org.hamcrest.CoreMatchers.equalTo;10import static org.junit.Assert.assertThat;11import java.util.EnumSet;12import java.util.List;13import org.hamcrest.CoreMatchers;14import org.hamcrest.Matchers;15import org.junit.Test;16import net.floodlightcontroller.core.IOFSwitchBackend;17import net.floodlightcontroller.core.SwitchDescription;18import net.floodlightcontroller.core.internal.OFSwitchHandshakeHandler.WaitAppHandshakeState;19import net.floodlightcontroller.core.internal.OFSwitchHandshakeHandler.WaitTableFeaturesReplyState;20import org.projectfloodlight.openflow.protocol.OFCapabilities;21import org.projectfloodlight.openflow.protocol.OFControllerRole;22import org.projectfloodlight.openflow.protocol.OFDescStatsReply;23import org.projectfloodlight.openflow.protocol.OFFactories;24import org.projectfloodlight.openflow.protocol.OFFactory;25import org.projectfloodlight.openflow.protocol.OFFeaturesReply;26import org.projectfloodlight.openflow.protocol.OFMessage;27import org.projectfloodlight.openflow.protocol.OFPortDesc;28import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply;29import org.projectfloodlight.openflow.protocol.OFPortDescStatsRequest;30import org.projectfloodlight.openflow.protocol.OFRoleReply;31import org.projectfloodlight.openflow.protocol.OFRoleRequest;32import org.projectfloodlight.openflow.protocol.OFTableFeaturesStatsReply;33import org.projectfloodlight.openflow.protocol.OFTableFeaturesStatsRequest;34import org.projectfloodlight.openflow.protocol.OFVersion;35import org.projectfloodlight.openflow.types.DatapathId;36import org.projectfloodlight.openflow.types.OFAuxId;37import org.projectfloodlight.openflow.types.OFPort;38import com.google.common.collect.ImmutableList;39public class OFSwitchHandshakeHandlerVer13Test extends OFSwitchHandlerTestBase {40 @Override41 public OFFactory getFactory() {42 return OFFactories.getFactory(OFVersion.OF_13);43 }44 @Override45 OFFeaturesReply getFeaturesReply() {46 return factory.buildFeaturesReply()47 .setDatapathId(dpid)48 .setNBuffers(1)49 .setNTables((short)1)50 .setCapabilities(EnumSet.<OFCapabilities>of(OFCapabilities.FLOW_STATS, OFCapabilities.TABLE_STATS))51 .setAuxiliaryId(OFAuxId.MAIN)52 .build();53 }54 OFPortDescStatsReply getPortDescStatsReply() {55 OFPortDesc portDesc = factory.buildPortDesc()56 .setName("Eth1")57 .setPortNo(OFPort.of(1))58 .build();59 return factory.buildPortDescStatsReply()60 .setEntries(ImmutableList.<OFPortDesc>of(portDesc))61 .build();62 }63 /** Move the channel from scratch to WAIT_CONFIG_REPLY state64 * Builds on moveToWaitFeaturesReply65 * adds testing for WAIT_FEATURES_REPLY state66 */67 @Test68 public void moveToWaitPortDescStatsReply() throws Exception {69 testInitState();70 switchHandler.beginHandshake();71 OFMessage msg = connection.retrieveMessage();72 assertThat(msg, CoreMatchers.instanceOf(OFPortDescStatsRequest.class));73 verifyUniqueXids(msg);74 assertThat(switchHandler.getStateForTesting(), CoreMatchers.instanceOf(OFSwitchHandshakeHandler.WaitPortDescStatsReplyState.class));75 }76 @Override77 void moveToPreConfigReply() throws Exception {78 moveToWaitPortDescStatsReply();79 switchHandler.processOFMessage(getPortDescStatsReply());80 }81 public void handleDescStatsAndCreateSwitch() throws Exception {82 // build the stats reply83 OFDescStatsReply sr = createDescriptionStatsReply();84 reset(sw);85 SwitchDescription switchDescription = new SwitchDescription(sr);86 setupSwitchForInstantiationWithReset();87 sw.setPortDescStats(anyObject(OFPortDescStatsReply.class));88 expectLastCall().once();89 90 expect(sw.getOFFactory()).andReturn(factory).anyTimes();91 replay(sw);92 reset(switchManager);93 expect(switchManager.getHandshakePlugins()).andReturn(plugins).anyTimes();94 expect(95 switchManager.getOFSwitchInstance(anyObject(OFConnection.class),96 eq(switchDescription),97 anyObject(OFFactory.class),98 anyObject(DatapathId.class))).andReturn(sw).once();99 expect(switchManager.getNumRequiredConnections()).andReturn(1).anyTimes(); 100 switchManager.switchAdded(sw);101 expectLastCall().once();102 replay(switchManager);103 // send the description stats reply104 switchHandler.processOFMessage(sr);105 OFMessage msg = connection.retrieveMessage();106 assertThat(msg, CoreMatchers.instanceOf(OFTableFeaturesStatsRequest.class));107 verifyUniqueXids(msg);108 109 verify(sw, switchManager);110 }111 112 @SuppressWarnings("unchecked")113 public void handleTableFeatures(boolean subHandShakeComplete) throws Exception {114 // build the table features stats reply115 OFTableFeaturesStatsReply tf = createTableFeaturesStatsReply();116 117 reset(sw);118 sw.startDriverHandshake();119 expectLastCall().once();120 expect(sw.isDriverHandshakeComplete()).andReturn(subHandShakeComplete).once();121 sw.processOFTableFeatures(anyObject(List.class));122 expectLastCall().once();123 expect(sw.getOFFactory()).andReturn(factory).anyTimes();124 replay(sw);125 126 switchHandler.processOFMessage(tf);127 }128 129 @Test130 public void moveToWaitTableFeaturesReplyState() throws Exception {131 moveToWaitDescriptionStatReply();132 handleDescStatsAndCreateSwitch();133 134 assertThat(switchHandler.getStateForTesting(),135 CoreMatchers.instanceOf(WaitTableFeaturesReplyState.class));136 }137 @Test138 @Override139 public void moveToWaitAppHandshakeState() throws Exception {140 moveToWaitTableFeaturesReplyState();141 handleTableFeatures(true);142 143 assertThat(switchHandler.getStateForTesting(),144 CoreMatchers.instanceOf(WaitAppHandshakeState.class));145 }146 @Override147 Class<?> getRoleRequestClass() {148 return OFRoleRequest.class;149 }150 @Override151 public void verifyRoleRequest(OFMessage m, OFControllerRole expectedRole) {152 assertThat(m, CoreMatchers.instanceOf(OFRoleRequest.class));153 OFRoleRequest roleRequest = (OFRoleRequest) m;154 assertThat(roleRequest.getRole(), equalTo(expectedRole));155 }156 @Override157 protected OFMessage getRoleReply(long xid, OFControllerRole role) {158 OFRoleReply roleReply = factory.buildRoleReply()159 .setXid(xid)160 .setRole(role)161 .build();162 return roleReply;163 }164 @Override165 @Test166 public void moveToWaitInitialRole() throws Exception {167 moveToWaitAppHandshakeState();168 assertThat(switchHandler.getStateForTesting(), CoreMatchers.instanceOf(WaitAppHandshakeState.class));169 reset(sw);170 expect(sw.getAttribute(IOFSwitchBackend.SWITCH_SUPPORTS_NX_ROLE)).andReturn(true).anyTimes();171 replay(sw);172 173 reset(roleManager);174 expect(roleManager.getOFControllerRole()).andReturn(OFControllerRole.ROLE_MASTER).anyTimes();175 roleManager.notifyControllerConnectionUpdate();176 expectLastCall().once();177 replay(roleManager);178 179 WaitAppHandshakeState state = (WaitAppHandshakeState) switchHandler.getStateForTesting();180 state.enterNextPlugin();181 // Expect wait initial role's enterState message to be written182 OFMessage msg = connection.retrieveMessage();183 assertThat(msg, CoreMatchers.instanceOf(OFRoleRequest.class));184 verifyUniqueXids(msg);185 assertThat(switchHandler.getStateForTesting(), CoreMatchers.instanceOf(OFSwitchHandshakeHandler.WaitInitialRoleState.class));186 }187 @Override188 @Test189 public void moveToWaitSwitchDriverSubHandshake() throws Exception {190 moveToWaitTableFeaturesReplyState();191 handleTableFeatures(false); //TODO192 assertThat(switchHandler.getStateForTesting(), CoreMatchers.instanceOf(OFSwitchHandshakeHandler.WaitSwitchDriverSubHandshakeState.class));193 assertThat("Unexpected message captured", connection.getMessages(), Matchers.empty());194 verify(sw);195 }196}...

Full Screen

Full Screen

Source:OFSwitchHandshakeHandlerVer10Test.java Github

copy

Full Screen

1package net.floodlightcontroller.core.internal;2import static org.easymock.EasyMock.anyObject;3import static org.easymock.EasyMock.eq;4import static org.easymock.EasyMock.expect;5import static org.easymock.EasyMock.expectLastCall;6import static org.easymock.EasyMock.replay;7import static org.easymock.EasyMock.reset;8import static org.easymock.EasyMock.verify;9import static org.hamcrest.CoreMatchers.equalTo;10import static org.hamcrest.CoreMatchers.instanceOf;11import static org.junit.Assert.assertThat;12import java.util.EnumSet;13import org.hamcrest.CoreMatchers;14import org.hamcrest.Matchers;15import org.junit.Test;16import net.floodlightcontroller.core.IOFSwitchBackend;17import net.floodlightcontroller.core.SwitchDescription;18import net.floodlightcontroller.core.internal.OFSwitchAppHandshakePlugin.PluginResultType;19import net.floodlightcontroller.core.internal.OFSwitchHandshakeHandler.WaitAppHandshakeState;20import org.projectfloodlight.openflow.protocol.OFActionType;21import org.projectfloodlight.openflow.protocol.OFCapabilities;22import org.projectfloodlight.openflow.protocol.OFControllerRole;23import org.projectfloodlight.openflow.protocol.OFDescStatsReply;24import org.projectfloodlight.openflow.protocol.OFFactories;25import org.projectfloodlight.openflow.protocol.OFFactory;26import org.projectfloodlight.openflow.protocol.OFFeaturesReply;27import org.projectfloodlight.openflow.protocol.OFMessage;28import org.projectfloodlight.openflow.protocol.OFNiciraControllerRoleReply;29import org.projectfloodlight.openflow.protocol.OFNiciraControllerRoleRequest;30import org.projectfloodlight.openflow.protocol.OFPortDesc;31import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply;32import org.projectfloodlight.openflow.protocol.OFType;33import org.projectfloodlight.openflow.protocol.OFVersion;34import org.projectfloodlight.openflow.types.DatapathId;35import org.projectfloodlight.openflow.types.OFPort;36import com.google.common.collect.ImmutableList;37public class OFSwitchHandshakeHandlerVer10Test extends OFSwitchHandlerTestBase {38 @Override39 public OFFactory getFactory() {40 return OFFactories.getFactory(OFVersion.OF_10);41 }42 @Override43 OFFeaturesReply getFeaturesReply() {44 OFPortDesc portDesc = factory.buildPortDesc()45 .setName("Eth1")46 .setPortNo(OFPort.of(1))47 .build();48 return factory.buildFeaturesReply()49 .setDatapathId(dpid)50 .setNBuffers(1)51 .setNTables((short)1)52 .setCapabilities(EnumSet.<OFCapabilities>of(OFCapabilities.FLOW_STATS, OFCapabilities.TABLE_STATS))53 .setActions(EnumSet.<OFActionType>of(OFActionType.SET_VLAN_PCP))54 .setPorts(ImmutableList.<OFPortDesc>of(portDesc))55 .build();56 }57 @Override58 void moveToPreConfigReply() throws Exception {59 testInitState();60 switchHandler.beginHandshake();61 }62 public void handleDescStatsAndCreateSwitch(boolean switchDriverComplete) throws Exception {63 // build the stats reply64 OFDescStatsReply sr = createDescriptionStatsReply();65 reset(sw);66 SwitchDescription switchDescription = new SwitchDescription(sr);67 setupSwitchForInstantiationWithReset();68 sw.startDriverHandshake();69 expectLastCall().once();70 expect(sw.getOFFactory()).andReturn(factory).once();71 sw.isDriverHandshakeComplete();72 expectLastCall().andReturn(switchDriverComplete).once();73 if(factory.getVersion().compareTo(OFVersion.OF_13) >= 0) {74 sw.setPortDescStats(anyObject(OFPortDescStatsReply.class));75 expectLastCall().once();76 }77 replay(sw);78 reset(switchManager);79 expect(switchManager.getHandshakePlugins()).andReturn(plugins).anyTimes();80 expect(81 switchManager.getOFSwitchInstance(anyObject(OFConnection.class),82 eq(switchDescription),83 anyObject(OFFactory.class),84 anyObject(DatapathId.class))).andReturn(sw).once();85 switchManager.switchAdded(sw);86 expectLastCall().once();87 replay(switchManager);88 // send the description stats reply89 switchHandler.processOFMessage(sr);90 }91 @Test92 @Override93 public void moveToWaitAppHandshakeState() throws Exception {94 moveToWaitDescriptionStatReply();95 handleDescStatsAndCreateSwitch(true);96 assertThat(switchHandler.getStateForTesting(),97 CoreMatchers.instanceOf(WaitAppHandshakeState.class));98 }99 @Override100 Class<?> getRoleRequestClass() {101 return OFNiciraControllerRoleRequest.class;102 }103 @Override104 public void verifyRoleRequest(OFMessage m, OFControllerRole expectedRole) {105 assertThat(m.getType(), equalTo(OFType.EXPERIMENTER));106 OFNiciraControllerRoleRequest roleRequest = (OFNiciraControllerRoleRequest)m;107 assertThat(roleRequest.getRole(), equalTo(NiciraRoleUtils.ofRoleToNiciraRole(expectedRole)));108 }109 @Override110 protected OFMessage getRoleReply(long xid, OFControllerRole role) {111 OFNiciraControllerRoleReply roleReply = factory.buildNiciraControllerRoleReply()112 .setXid(xid)113 .setRole(NiciraRoleUtils.ofRoleToNiciraRole(role))114 .build();115 return roleReply;116 }117 @Override118 @Test119 public void moveToWaitSwitchDriverSubHandshake() throws Exception {120 moveToWaitDescriptionStatReply();121 handleDescStatsAndCreateSwitch(false);122 assertThat(switchHandler.getStateForTesting(), CoreMatchers.instanceOf(OFSwitchHandshakeHandler.WaitSwitchDriverSubHandshakeState.class));123 assertThat("Unexpected message captured", connection.getMessages(), Matchers.empty());124 verify(sw);125 }126 @Override127 @Test128 public void moveToWaitInitialRole()129 throws Exception {130 moveToWaitAppHandshakeState();131 assertThat(switchHandler.getStateForTesting(),132 CoreMatchers.instanceOf(WaitAppHandshakeState.class));133 reset(sw);134 expect(sw.getAttribute(IOFSwitchBackend.SWITCH_SUPPORTS_NX_ROLE)).andReturn(true).anyTimes();135 replay(sw);136 reset(roleManager);137 expect(roleManager.getOFControllerRole()).andReturn(OFControllerRole.ROLE_MASTER).anyTimes();138 replay(roleManager);139 WaitAppHandshakeState state = (WaitAppHandshakeState) switchHandler.getStateForTesting();140 PluginResult result = new PluginResult(PluginResultType.CONTINUE);141 state.exitPlugin(result);142 assertThat(connection.retrieveMessage(), instanceOf(getRoleRequestClass()));143 assertThat(switchHandler.getStateForTesting(), CoreMatchers.instanceOf(OFSwitchHandshakeHandler.WaitInitialRoleState.class));144 }145}...

Full Screen

Full Screen

InstanceOf

Using AI Code Generation

copy

Full Screen

1import org.easymock.internal.matchers.InstanceOf;2import org.easymock.EasyMock;3import org.easymock.IMocksControl;4import org.easymock.internal.matchers.InstanceOf;5import org.junit.Assert;6import org.junit.Test;7public class InstanceOfTest {8 IMocksControl control = EasyMock.createControl();9 public void testInstanceOf() {10 String mockObject = control.createMock(String.class);11 InstanceOf instanceOf = new InstanceOf(String.class);12 EasyMock.expect(mockObject).andReturn("Hello").andStubReturn("World");13 control.replay();14 Assert.assertEquals("Hello", mockObject);15 Assert.assertTrue(instanceOf.matches("Hello"));16 Assert.assertFalse(instanceOf.matches(1));17 Assert.assertFalse(instanceOf.matches(new Long(1)));18 Assert.assertFalse(instanceOf.matches(new Double(1)));19 Assert.assertFalse(instanceOf.matches(new Float(1)));20 Assert.assertFalse(instanceOf.matches(new Character('a')));21 Assert.assertFalse(instanceOf.matches(new Boolean(true)));22 Assert.assertFalse(instanceOf.matches(new Short("1")));23 Assert.assertFalse(instanceOf.matches(new Byte("1")));24 control.verify();25 }26}

Full Screen

Full Screen

InstanceOf

Using AI Code Generation

copy

Full Screen

1import org.easymock.EasyMock;2import org.easymock.EasyMockSupport;3import org.easymock.internal.matchers.InstanceOf;4import org.junit.Test;5import static org.easymock.EasyMock.expect;6import static org.easymock.EasyMock.expectLastCall;7import static org.easymock.EasyMock.isA;8import static org.easymock.EasyMock.replay;9import static org.easymock.EasyMock.verify;10import static org.junit.Assert.assertEquals;11import static org.junit.Assert.assertTrue;12import static org.junit.Assert.fail;13import java.util.List;14public class Test1 {15 public void test1() {16 List mock = EasyMock.createMock(List.class);17 mock.add("one");18 expectLastCall().andThrow(new RuntimeException());19 replay(mock);20 try {21 mock.add("one");22 fail("should have thrown exception");23 } catch (RuntimeException expected) {24 }25 verify(mock);26 }27 public void test2() {28 List mock = EasyMock.createMock(List.class);29 mock.add("one");30 expectLastCall().andThrow(new RuntimeException());31 replay(mock);32 try {33 mock.add("one");34 fail("should have thrown exception");35 } catch (RuntimeException expected) {36 }37 verify(mock);38 }39 public void test3() {40 List mock = EasyMock.createMock(List.class);41 mock.add("one");42 expectLastCall().andThrow(new RuntimeException());43 replay(mock);44 try {45 mock.add("one");46 fail("should have thrown exception");47 } catch (RuntimeException expected) {48 }49 verify(mock);50 }51 public void test4() {52 List mock = EasyMock.createMock(List.class);53 mock.add("one");54 expectLastCall().andThrow(new RuntimeException());55 replay(mock);56 try {57 mock.add("one");58 fail("should have thrown exception");59 } catch (RuntimeException expected) {60 }61 verify(mock);62 }63 public void test5() {64 List mock = EasyMock.createMock(List.class);65 mock.add("one");66 expectLastCall().andThrow(new RuntimeException());67 replay(mock);68 try {69 mock.add("one");

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Easymock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in InstanceOf

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful