@Test public void testCompatibleExtensionTogetherSuccess() { // initialize expect(mainHandshakerMock.handshakeExtension(webSocketExtensionDataEqual("main"))) .andReturn(mainExtensionMock) .anyTimes(); expect(mainHandshakerMock.handshakeExtension(webSocketExtensionDataEqual("fallback"))) .andReturn(null) .anyTimes(); replay(mainHandshakerMock); expect(fallbackHandshakerMock.handshakeExtension(webSocketExtensionDataEqual("fallback"))) .andReturn(fallbackExtensionMock) .anyTimes(); expect(fallbackHandshakerMock.handshakeExtension(webSocketExtensionDataEqual("main"))) .andReturn(null) .anyTimes(); replay(fallbackHandshakerMock); expect(mainExtensionMock.rsv()).andReturn(WebSocketExtension.RSV1).anyTimes(); expect(mainExtensionMock.newReponseData()) .andReturn(new WebSocketExtensionData("main", Collections.<String, String>emptyMap())) .once(); expect(mainExtensionMock.newExtensionEncoder()).andReturn(new DummyEncoder()).once(); expect(mainExtensionMock.newExtensionDecoder()).andReturn(new DummyDecoder()).once(); replay(mainExtensionMock); expect(fallbackExtensionMock.rsv()).andReturn(WebSocketExtension.RSV2).anyTimes(); expect(fallbackExtensionMock.newReponseData()) .andReturn(new WebSocketExtensionData("fallback", Collections.<String, String>emptyMap())) .once(); expect(fallbackExtensionMock.newExtensionEncoder()).andReturn(new Dummy2Encoder()).once(); expect(fallbackExtensionMock.newExtensionDecoder()).andReturn(new Dummy2Decoder()).once(); replay(fallbackExtensionMock); // execute EmbeddedChannel ch = new EmbeddedChannel( new WebSocketServerExtensionHandler(mainHandshakerMock, fallbackHandshakerMock)); HttpRequest req = newUpgradeRequest("main, fallback"); ch.writeInbound(req); HttpResponse res = newUpgradeResponse(null); ch.writeOutbound(res); HttpResponse res2 = ch.readOutbound(); List<WebSocketExtensionData> resExts = WebSocketExtensionUtil.extractExtensions( res2.headers().getAndConvert(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS)); // test assertEquals(2, resExts.size()); assertEquals("main", resExts.get(0).name()); assertEquals("fallback", resExts.get(1).name()); assertNotNull(ch.pipeline().get(DummyDecoder.class)); assertNotNull(ch.pipeline().get(DummyEncoder.class)); assertNotNull(ch.pipeline().get(Dummy2Decoder.class)); assertNotNull(ch.pipeline().get(Dummy2Encoder.class)); }
@Test public void events() { // new host testProcessor.process(new TestArpPacketContext(DEV1)); assertNotNull("new host expected", providerService.added); assertNull("host motion unexpected", providerService.moved); // the host moved to new switch testProcessor.process(new TestArpPacketContext(DEV2)); assertNotNull("host motion expected", providerService.moved); // the host was misheard on a spine testProcessor.process(new TestArpPacketContext(DEV3)); assertNull("host misheard on spine switch", providerService.spine); providerService.clear(); // new host testProcessor.process(new TestNaPacketContext(DEV4)); assertNotNull("new host expected", providerService.added); assertNull("host motion unexpected", providerService.moved); // the host moved to new switch testProcessor.process(new TestNaPacketContext(DEV5)); assertNotNull("host motion expected", providerService.moved); // the host was misheard on a spine testProcessor.process(new TestNaPacketContext(DEV6)); assertNull("host misheard on spine switch", providerService.spine); }
@Test public void testRunnableWrappsRunnable() throws Exception { final Object mockChannel = createMock("mockChannel", AbstractAioChannel.class); replay(mockChannel); final Runnable r = new Runnable() { @SuppressWarnings("unused") @Override public void run() { Object channel = mockChannel; // Noop } }; Runnable r2 = new Runnable() { @SuppressWarnings("unused") @Override public void run() { Runnable runnable = r; // Noop } }; AioChannelFinder finder = create(); AbstractAioChannel channel = finder.findChannel(r2); assertNotNull(channel); AbstractAioChannel channel2 = finder.findChannel(r2); assertNotNull(channel2); assertSame(channel2, channel); verify(mockChannel); reset(mockChannel); }
protected void fileRoundTripTesting() throws Exception { message("File round trip testing ..."); int expectedSize = putFile(); assertNotNull("check checksum is not null", checksumObserver.getActualChecksum()); assertEquals( "compare checksums", "6b144b7285ffd6b0bc8300da162120b9", checksumObserver.getActualChecksum()); checksumObserver = new ChecksumObserver(); getFile(expectedSize); assertNotNull("check checksum is not null", checksumObserver.getActualChecksum()); assertEquals( "compare checksums", "6b144b7285ffd6b0bc8300da162120b9", checksumObserver.getActualChecksum()); // Now compare the conents of the artifact that was placed in // the repository with the contents of the artifact that was // retrieved from the repository. String sourceContent = FileUtils.fileRead(sourceFile); String destContent = FileUtils.fileRead(destFile); assertEquals(sourceContent, destContent); }
@BeforeMethod public void setUp() throws Exception { cleanupDB(); m_mockStoreManager = EasyMock.createMock(IActiveMailboxStoreManager.class); ICustomerManager customerMgrMock = new CustomerManagerMock(); IIslandManager islandMgrMock = createNiceMock(IIslandManager.class); int islandId = 0; // needs to match value for feed/search passed into TestUtils.createCustomer() call to // customer manager boolean provisioned = true; // needs to be provisioned-enabled Island island = new Island(islandId, "fooIsland", null, provisioned, false, "fooPlatform", "fooSchema"); expect(islandMgrMock.getIsland(islandId)).andReturn(island).anyTimes(); expect(islandMgrMock.isValidIsland(islandId)).andReturn(true).anyTimes(); replay(islandMgrMock); ManagementContainerInjector.getInjector() .withService(islandMgrMock, getClass().getName()) .withService(customerMgrMock, getClass().getName()); m_customer = TestUtils.createActiveMailboxTestCustomer( Capabilities.ActiveMailboxSupport.AM_CUSTOMER_ENCRYPTION); assertNotNull("Customer should have been created", m_customer); TestUtils.cleanupTestUsers(m_customer.getCustID()); m_user = TestUtils.createUser(m_customer, "user-1", "1", "password"); assertNotNull("User should have been created", m_user); }
public void testReportExporting() { String siteId = null; Report r = null; ReportParams rp = null; List<String> totalsBy = null; siteId = FakeData.SITE_A_ID; ReportDef rd = new ReportDef(); rd.setId(0); rd.setSiteId(siteId); rd.setCreatedBy(FakeData.USER_A_ID); rd.setModifiedBy(FakeData.USER_A_ID); rd.setTitle("Title 1"); rp = new ReportParams(siteId); rp.setWhat(ReportManager.WHAT_RESOURCES); rp.setWhen(ReportManager.WHEN_ALL); rp.setWho(ReportManager.WHO_ALL); totalsBy = new ArrayList<String>(); totalsBy.add(StatsManager.T_SITE); totalsBy.add(StatsManager.T_USER); rp.setHowTotalsBy(totalsBy); rp.setHowSort(false); rp.setHowPresentationMode(ReportManager.HOW_PRESENTATION_TABLE); rd.setReportParams(rp); Report report = M_rm.getReport(rd, false); assertNotNull(report); // CSV String csv = M_rm.getReportAsCsv(report); assertNotNull(csv); assertTrue(csv.length() > 0); // EXCEL byte[] excel = M_rm.getReportAsExcel(report, "sheetname"); assertNotNull(excel); assertTrue(excel.length > 0); // To verify locally... // File file = new File("d:/sitestats-test.xls"); // if(file.exists()) {file.delete();} // FileOutputStream out = null; // try{ // out = new FileOutputStream(file); // out.write(excel); // out.flush(); // }catch(FileNotFoundException e){ // e.printStackTrace(); // }catch(IOException e){ // e.printStackTrace(); // }finally{ // if(out != null) { // try{ out.close(); }catch(IOException e){ /* IGNORE */} // } // } // PDF: currently disabled due to classloading trouble // byte[] pdf = M_rm.getReportAsPDF(report); // assertNotNull(pdf); // assertTrue(pdf.length > 0); }
@Test public void testCreate() { projectAction.setProject(null); projectAction.create(); assertNotNull(projectAction.getProject()); assertNotNull(projectAction.getProject().getStartDate()); assertNotNull(projectAction.getProject().getEndDate()); }
private void verifyActions(OFFlowMod testFlowMod, OFFlowMod goodFlowMod) { List<OFAction> goodActions = goodFlowMod.getActions(); List<OFAction> testActions = testFlowMod.getActions(); assertNotNull(goodActions); assertNotNull(testActions); assertEquals(goodActions.size(), testActions.size()); // assumes actions are marshalled in same order; should be safe for (int i = 0; i < goodActions.size(); i++) { assertEquals(goodActions.get(i), testActions.get(i)); } }
@Test /* This test tests internal working of the class alone */ public void testCreateInterface() { vr.createInterface("if1", "netVirt1", null, true); assertNotNull(vr.getInterfaceMap().get("if1")); assertEquals(true, vr.getInterfaceMap().get("if1").isNetVirt()); vr.createInterface("if2", null, "rtr1", true); assertNotNull(vr.getInterfaceMap().get("if2")); assertEquals(false, vr.getInterfaceMap().get("if2").isNetVirt()); assertEquals(2, vr.getInterfaceMap().size()); }
/** * Test {@link Wagon#getFileList(String)}. * * @throws Exception * @since 1.0-beta-2 */ public void testWagonGetFileList() throws Exception { setupRepositories(); setupWagonTestingFixtures(); String dirName = "file-list"; String filenames[] = new String[] { "test-resource.txt", "test-resource.pom", "test-resource b.txt", "more-resources.dat", ".index.txt" }; for (String filename : filenames) { putFile(dirName + "/" + filename, dirName + "/" + filename, filename + "\n"); } Wagon wagon = getWagon(); wagon.connect(testRepository, getAuthInfo()); List<String> list = wagon.getFileList(dirName); assertNotNull("file list should not be null.", list); assertTrue( "file list should contain more items (actually contains '" + list + "').", list.size() >= filenames.length); for (String filename : filenames) { assertTrue("Filename '" + filename + "' should be in list.", list.contains(filename)); } // WAGON-250 list = wagon.getFileList(""); assertNotNull("file list should not be null.", list); assertTrue( "file list should contain items (actually contains '" + list + "').", !list.isEmpty()); assertTrue(list.contains("file-list/")); assertFalse(list.contains("file-list")); assertFalse(list.contains(".")); assertFalse(list.contains("..")); assertFalse(list.contains("./")); assertFalse(list.contains("../")); wagon.disconnect(); tearDownWagonTestingFixtures(); }
/* * Note: The following tests on the gateway pool/node related APIs in * VirutalRouterImpl class ensure only that the IGatewayPool API usage is * correct. It does not cover in detail the test cases for the IGatewayPool * APIs. Please refer GatewayPoolTest.java for detailed tests on the * IGatewayPool interface. */ @Test public void testCreateGatewayPool() { String gatewayPoolName1 = "testGatewayPool1"; vr.createGatewayPool(gatewayPoolName1); GatewayPoolImpl gatewayPool1 = vr.getGatewayPool(gatewayPoolName1); assertNotNull(gatewayPool1); assertEquals("testGatewayPool1", gatewayPool1.getName()); String gatewayPoolName2 = "testGatewayPool2"; vr.createGatewayPool(gatewayPoolName2); GatewayPoolImpl gatewayPool2 = vr.getGatewayPool(gatewayPoolName2); assertNotNull(gatewayPool2); assertEquals("testGatewayPool2", gatewayPool2.getName()); }
public void testConnectionFailure() throws Exception { // create mock objects that will simulate a connection failure GSSClient client = createMock(GSSClient.class); expect(client.getCentralRevision((QName) anyObject())) .andThrow(new IOException("Host unreachable")); replay(client); GSSClientFactory factory = createMock(GSSClientFactory.class); expect(factory.createClient(new URL("http://localhost:8081/geoserver/ows"), null, null)) .andReturn(client); replay(factory); synch.clientFactory = factory; // perform synch Date start = new Date(); synch.synchronizeOustandlingLayers(); Date end = new Date(); // check we stored the last failure marker SimpleFeature f = getSingleFeature(fsUnitTables, ff.equal(ff.property("table_id"), ff.literal(1), false)); Date lastFailure = (Date) f.getAttribute("last_failure"); assertNotNull(lastFailure); assertTrue(lastFailure.compareTo(start) >= 0 && lastFailure.compareTo(end) <= 0); // check we marked the unit as failed f = getSingleFeature(fsUnits, ff.equal(ff.property("unit_name"), ff.literal("unit1"), false)); assertTrue((Boolean) f.getAttribute("errors")); }
private void invoke(boolean extendToInterfaces) throws NoSuchMethodException, Throwable { FilterService fs = createMock(FilterService.class); IService service = createMock(IService.class); // expect int paramValue = 10; Object retValue = new Object(); Method method = IService.class.getDeclaredMethod("test0", int.class); expect(fs.invoke(service, extendToInterfaces, method, paramValue)).andReturn(retValue); // replay replay(service, fs); // test FilterInterceptor fi = new FilterInterceptor(); fi.setFilterService(fs); fi.setExtendToInterfaces(extendToInterfaces); MethodInvocation mi = new TestMethodInvocation(service, method, new Object[] {paramValue}); Object ret = fi.invoke(mi); // check verify(service, fs); assertNotNull("Result must not be null", ret); assertEquals("FilterService must be called", retValue, ret); }
// Approve a subscription while the server already has a Buddies group @Test public void testApproveSubscription_serverBuddies() throws Exception { expectInitialListCreation(); Capture<RosterListener> listenerCapture = new Capture<RosterListener>(); roster.addRosterListener(capture(listenerCapture)); expectLastCall(); subscriptionRequestListener.onSubscriptionApproved(TEST_CONTACT); expectLastCall(); smackCon.sendPacket(anyObject(Packet.class)); expectLastCall(); final ArrayList<RosterGroup> groups = new ArrayList<RosterGroup>(); RosterGroup buddiesGroup = createNiceMock(RosterGroup.class); expect(buddiesGroup.getName()).andStubReturn(DEFAULT_GROUP_NAME); expect(buddiesGroup.getEntries()).andStubReturn(new ArrayList<RosterEntry>()); groups.add(buddiesGroup); expect(roster.getGroups()).andReturn(groups); expect(roster.getUnfiledEntryCount()).andStubReturn(0); roster.createEntry( eq(TEST_CONTACT), eq(TEST_CONTACT_NAME), aryEq(new String[] {DEFAULT_GROUP_NAME})); expectLastCall(); listener.onContactChange( eq(ContactListListener.LIST_CONTACT_ADDED), anyObject(ContactList.class), anyObject(Contact.class)); expectLastCall(); replayAll(); contactListManager.listenToRoster(roster); contactListManager.loadContactLists(); contactListManager.approveSubscriptionRequest(TEST_CONTACT); assertEquals(1, contactListManager.getContactLists().size()); assertNotNull(contactListManager.getContactList(DEFAULT_GROUP_NAME)); assertTrue(con.joinGracefully()); verifyAll(); }
@Test public void testApproveSubscription() throws Exception { expectInitialListCreation(); Capture<RosterListener> listenerCapture = new Capture<RosterListener>(); roster.addRosterListener(capture(listenerCapture)); expectLastCall(); subscriptionRequestListener.onSubscriptionApproved(TEST_CONTACT); expectLastCall().times(2); smackCon.sendPacket(anyObject(Packet.class)); expectLastCall().times(2); expect(roster.getGroups()).andReturn(new ArrayList<RosterGroup>()); expect(roster.getUnfiledEntryCount()).andStubReturn(0); roster.createEntry( eq(TEST_CONTACT), eq(TEST_CONTACT_NAME), aryEq(new String[] {DEFAULT_GROUP_NAME})); expectLastCall().times(2); listener.onContactChange( eq(ContactListListener.LIST_CONTACT_ADDED), anyObject(ContactList.class), anyObject(Contact.class)); expectLastCall(); replayAll(); contactListManager.listenToRoster(roster); contactListManager.loadContactLists(); contactListManager.approveSubscriptionRequest(TEST_CONTACT); // Second time should not call notifyContactListUpdated, since contact // already exists contactListManager.approveSubscriptionRequest(TEST_CONTACT); assertEquals(1, contactListManager.getContactLists().size()); assertNotNull(contactListManager.getContactList(DEFAULT_GROUP_NAME)); assertTrue(con.joinGracefully()); verifyAll(); }
@Test public void test_includeApplicationDefaultCSS_emptyList() { replayDefault(); List<CSS> cssList = cssCommand.includeApplicationDefaultCSS(); assertNotNull(cssList); verifyDefault(); }
@Test public void testSetStartDate_null() { Date startDate = cal.getStartDate(); cal.setStartDate(null); assertNotNull(cal.getStartDate()); assertSame(startDate, cal.getStartDate()); }
public void testGetLatestAlbums() throws SQLException { final Properties p = createMock(Properties.class); expect(p.get(Constants.WWW_BROWSE_LATEST_ALBUMS_COUNT, 10)).andReturn(10l); replay(p); final ResultSet rs = createNiceMock(ResultSet.class); expect(rs.next()).andReturn(true); expect(rs.next()).andReturn(true); expect(rs.next()).andReturn(false); replay(rs); final PreparedStatement st = createMock(PreparedStatement.class); st.setInt(1, 10); expect(st.executeQuery()).andReturn(rs).times(1); replay(st); final Database db = createMock(Database.class); expect(db.prepare((String) anyObject())).andReturn(st).times(1); replay(db); final Latester b = new Latester(); b.setProperties(p); b.setDatabase(db); final Vector<Album> albums = b.getLatestAlbums(); assertNotNull(albums); assertEquals(2, albums.size()); verify(db); verify(st); verify(rs); verify(p); }
protected void assertGetIfNewerTest( ProgressAnswer progressAnswer, boolean expectedResult, int expectedSize) throws IOException { if (expectedResult) { verifyMock(progressAnswer, expectedSize); assertNotNull("check checksum is not null", checksumObserver.getActualChecksum()); assertEquals( "compare checksums", "6b144b7285ffd6b0bc8300da162120b9", checksumObserver.getActualChecksum()); // Now compare the contents of the artifact that was placed in // the repository with the contents of the artifact that was // retrieved from the repository. String sourceContent = FileUtils.fileRead(sourceFile); String destContent = FileUtils.fileRead(destFile); assertEquals(sourceContent, destContent); } else { verify(mockTransferListener); reset(mockTransferListener); assertNull("check checksum is null", checksumObserver.getActualChecksum()); assertFalse(destFile.exists()); } }
@Test public void testGetRoleInfoDefault() { RoleInfo info = controller.getRoleInfo(); assertEquals(HARole.ACTIVE, info.getRole()); assertNotNull(info.getRoleChangeDescription()); assertEquals(HARole.ACTIVE, controller.getRole()); // FIXME: RoleInfo's date. but the format is kinda broken }
private static void assertDevice(DeviceId id, String swVersion, Device device) { assertNotNull(device); assertEquals(id, device.id()); assertEquals(MFR, device.manufacturer()); assertEquals(HW, device.hwVersion()); assertEquals(swVersion, device.swVersion()); assertEquals(SN, device.serialNumber()); }
@Test public void testSaveState() { FacesContext context = EasyMock.createMock(FacesContext.class); UIInput input = new UIInput(); replay(context); assertNotNull(input.saveState(context)); verify(context); }
@Test public void constructorWorksWhenNonNullFactoryProvided() { KeystrokeFactory mockFactory = createMock(KeystrokeFactory.class); replayMock(mockFactory); KeystrokeRecorderImpl recorder = new KeystrokeRecorderImpl(mockFactory); assertNotNull(recorder); }
@Test public void testSetStartDate() { Date startDate = cal.getStartDate(); Date newStartDate = new Date(); cal.setStartDate(newStartDate); assertNotNull(cal.getStartDate()); assertNotSame(startDate, cal.getStartDate()); assertSame(newStartDate, cal.getStartDate()); }
@Test public void test_includeApplicationDefaultCSS_registerMockComponent_emptyList() throws Exception { ICssExtensionRole testCssExtMock = registerComponentMock(ICssExtensionRole.class, "testCssExt"); expect(testCssExtMock.getCssList()).andReturn(Collections.<CSS>emptyList()).once(); replayDefault(); List<CSS> cssList = cssCommand.includeApplicationDefaultCSS(); assertNotNull(cssList); verifyDefault(); }
@Test public void testRestoreState3() { FacesContext context = EasyMock.createMock(FacesContext.class); UIInput input = new UIInput(); replay(context); Object state = input.saveState(context); assertNotNull(state); input.restoreState(context, state); verify(context); }
@Test public void testAddGatewayNode() { String gatewayPoolName = "testGatewayPool"; vr.createGatewayPool(gatewayPoolName); vr.addGatewayPoolNode(gatewayPoolName, "10.0.0.1"); vr.addGatewayPoolNode(gatewayPoolName, "10.0.0.2"); GatewayPoolImpl gatewayPool = vr.getGatewayPool(gatewayPoolName); assertNotNull(gatewayPool); assertEquals("testGatewayPool", gatewayPool.getName()); Map<String, GatewayNode> nodes = gatewayPool.getGatewayNodes(); assertNotNull(nodes); assertEquals(2, nodes.size()); GatewayNode node1 = nodes.get("10.0.0.1"); assertEquals("10.0.0.1", IPv4.fromIPv4Address(node1.getIp())); GatewayNode node2 = nodes.get("10.0.0.2"); assertEquals("10.0.0.2", IPv4.fromIPv4Address(node2.getIp())); }
/** When receiving NeighborAdvertisement, updates location and IP. */ @Test public void testReceiveNa() { testProcessor.process(new TestNaPacketContext(DEV4)); assertNotNull(providerService.added); HostDescription descr = providerService.added; assertThat(descr.location(), is(LOCATION2)); assertThat(descr.hwAddress(), is(MAC2)); assertThat(descr.ipAddress().toArray()[0], is(IP_ADDRESS2)); assertThat(descr.vlan(), is(VLAN)); }
/** When receiving IPv6 unicast packet, updates location only. */ @Test public void testReceiveIpv6Unicast() { testProcessor.process(new TestIpv6PacketContext(DEV4)); assertNotNull(providerService.added); HostDescription descr = providerService.added; assertThat(descr.location(), is(LOCATION2)); assertThat(descr.hwAddress(), is(MAC2)); assertThat(descr.ipAddress().size(), is(0)); assertThat(descr.vlan(), is(VLAN)); }
@Test public void test_includeApplicationDefaultCSS_registerMockComponent_oneElem() throws Exception { ICssExtensionRole testCssExtMock = registerComponentMock(ICssExtensionRole.class, "testCssExt"); expect(testCssExtMock.getCssList()) .andReturn(Arrays.<CSS>asList(new CSSString(":celRes/test.css", getContext()))) .once(); replayDefault(); List<CSS> cssList = cssCommand.includeApplicationDefaultCSS(); assertNotNull(cssList); verifyDefault(); }