@Test public void testResetOriginalValues() throws Exception { CalendarResource newCalendarResource = addCalendarResource(); _persistence.clearCache(); CalendarResource existingCalendarResource = _persistence.findByPrimaryKey(newCalendarResource.getPrimaryKey()); Assert.assertTrue( Validator.equals( existingCalendarResource.getUuid(), ReflectionTestUtil.invoke( existingCalendarResource, "getOriginalUuid", new Class<?>[0]))); Assert.assertEquals( Long.valueOf(existingCalendarResource.getGroupId()), ReflectionTestUtil.<Long>invoke( existingCalendarResource, "getOriginalGroupId", new Class<?>[0])); Assert.assertEquals( Long.valueOf(existingCalendarResource.getClassNameId()), ReflectionTestUtil.<Long>invoke( existingCalendarResource, "getOriginalClassNameId", new Class<?>[0])); Assert.assertEquals( Long.valueOf(existingCalendarResource.getClassPK()), ReflectionTestUtil.<Long>invoke( existingCalendarResource, "getOriginalClassPK", new Class<?>[0])); }
@Test public void testResetOriginalValues() throws Exception { JournalContentSearch newJournalContentSearch = addJournalContentSearch(); _persistence.clearCache(); JournalContentSearch existingJournalContentSearch = _persistence.findByPrimaryKey(newJournalContentSearch.getPrimaryKey()); Assert.assertEquals( existingJournalContentSearch.getGroupId(), ReflectionTestUtil.invoke( existingJournalContentSearch, "getOriginalGroupId", new Class<?>[0])); Assert.assertEquals( existingJournalContentSearch.getPrivateLayout(), ReflectionTestUtil.invoke( existingJournalContentSearch, "getOriginalPrivateLayout", new Class<?>[0])); Assert.assertEquals( existingJournalContentSearch.getLayoutId(), ReflectionTestUtil.invoke( existingJournalContentSearch, "getOriginalLayoutId", new Class<?>[0])); Assert.assertTrue( Validator.equals( existingJournalContentSearch.getPortletId(), ReflectionTestUtil.invoke( existingJournalContentSearch, "getOriginalPortletId", new Class<?>[0]))); Assert.assertTrue( Validator.equals( existingJournalContentSearch.getArticleId(), ReflectionTestUtil.invoke( existingJournalContentSearch, "getOriginalArticleId", new Class<?>[0]))); }
@Test public void testResetOriginalValues() throws Exception { MBDiscussion newMBDiscussion = addMBDiscussion(); _persistence.clearCache(); MBDiscussion existingMBDiscussion = _persistence.findByPrimaryKey(newMBDiscussion.getPrimaryKey()); Assert.assertTrue( Validator.equals( existingMBDiscussion.getUuid(), ReflectionTestUtil.invoke(existingMBDiscussion, "getOriginalUuid", new Class<?>[0]))); Assert.assertEquals( Long.valueOf(existingMBDiscussion.getGroupId()), ReflectionTestUtil.<Long>invoke( existingMBDiscussion, "getOriginalGroupId", new Class<?>[0])); Assert.assertEquals( Long.valueOf(existingMBDiscussion.getThreadId()), ReflectionTestUtil.<Long>invoke( existingMBDiscussion, "getOriginalThreadId", new Class<?>[0])); Assert.assertEquals( Long.valueOf(existingMBDiscussion.getClassNameId()), ReflectionTestUtil.<Long>invoke( existingMBDiscussion, "getOriginalClassNameId", new Class<?>[0])); Assert.assertEquals( Long.valueOf(existingMBDiscussion.getClassPK()), ReflectionTestUtil.<Long>invoke( existingMBDiscussion, "getOriginalClassPK", new Class<?>[0])); }
@Test public void testSoftKeyWeakValue() throws InterruptedException { System.setProperty(FinalizeManager.class.getName() + ".thread.enabled", StringPool.FALSE); String testKey1 = new String("testKey1"); String testKey2 = new String("testKey2"); Object testValue1 = new Object(); Object testValue2 = new Object(); ConcurrentMap<String, Object> concurrentReferenceMap = new ConcurrentReferenceKeyHashMap<String, Object>( new ConcurrentReferenceValueHashMap<Reference<String>, Object>( FinalizeManager.WEAK_REFERENCE_FACTORY), FinalizeManager.SOFT_REFERENCE_FACTORY); Assert.assertNull(concurrentReferenceMap.put(testKey1, testValue1)); Assert.assertNull(concurrentReferenceMap.put(testKey2, testValue2)); Assert.assertEquals(2, concurrentReferenceMap.size()); Assert.assertTrue(concurrentReferenceMap.containsKey(testKey1)); Assert.assertTrue(concurrentReferenceMap.containsValue(testValue1)); Assert.assertSame(testValue1, concurrentReferenceMap.get(testKey1)); Assert.assertTrue(concurrentReferenceMap.containsKey(testKey2)); Assert.assertTrue(concurrentReferenceMap.containsValue(testValue2)); Assert.assertSame(testValue2, concurrentReferenceMap.get(testKey2)); testKey1 = null; GCUtil.gc(true); ReflectionTestUtil.invoke(FinalizeManager.class, "_pollingCleanup", new Class<?>[0]); Assert.assertEquals(2, concurrentReferenceMap.size()); Assert.assertTrue(concurrentReferenceMap.containsValue(testValue1)); Assert.assertTrue(concurrentReferenceMap.containsKey(testKey2)); Assert.assertTrue(concurrentReferenceMap.containsValue(testValue2)); Assert.assertSame(testValue2, concurrentReferenceMap.get(testKey2)); GCUtil.fullGC(true); ReflectionTestUtil.invoke(FinalizeManager.class, "_pollingCleanup", new Class<?>[0]); Assert.assertEquals(1, concurrentReferenceMap.size()); Assert.assertTrue(concurrentReferenceMap.containsKey(testKey2)); Assert.assertTrue(concurrentReferenceMap.containsValue(testValue2)); Assert.assertSame(testValue2, concurrentReferenceMap.get(testKey2)); testValue2 = null; GCUtil.gc(true); ReflectionTestUtil.invoke(FinalizeManager.class, "_pollingCleanup", new Class<?>[0]); Assert.assertTrue(concurrentReferenceMap.isEmpty()); }
@Test public void testResetOriginalValues() throws Exception { LayoutSet newLayoutSet = addLayoutSet(); _persistence.clearCache(); LayoutSet existingLayoutSet = _persistence.findByPrimaryKey(newLayoutSet.getPrimaryKey()); Assert.assertEquals( existingLayoutSet.getGroupId(), ReflectionTestUtil.invoke(existingLayoutSet, "getOriginalGroupId", new Class<?>[0])); Assert.assertEquals( existingLayoutSet.getPrivateLayout(), ReflectionTestUtil.invoke(existingLayoutSet, "getOriginalPrivateLayout", new Class<?>[0])); }
@Test public void testResetOriginalValues() throws Exception { KaleoTaskInstanceToken newKaleoTaskInstanceToken = addKaleoTaskInstanceToken(); _persistence.clearCache(); KaleoTaskInstanceToken existingKaleoTaskInstanceToken = _persistence.findByPrimaryKey(newKaleoTaskInstanceToken.getPrimaryKey()); Assert.assertEquals( Long.valueOf(existingKaleoTaskInstanceToken.getKaleoInstanceId()), ReflectionTestUtil.<Long>invoke( existingKaleoTaskInstanceToken, "getOriginalKaleoInstanceId", new Class<?>[0])); Assert.assertEquals( Long.valueOf(existingKaleoTaskInstanceToken.getKaleoTaskId()), ReflectionTestUtil.<Long>invoke( existingKaleoTaskInstanceToken, "getOriginalKaleoTaskId", new Class<?>[0])); }
protected void testIsValidByMethodName(String methodName, String[] params, boolean valid) { for (String param : params) { Assert.assertEquals( valid, ReflectionTestUtil.invoke( Validator.class, methodName, new Class<?>[] {String.class}, param)); } }
@Test public void testResetOriginalValues() throws Exception { MeetupsRegistration newMeetupsRegistration = addMeetupsRegistration(); _persistence.clearCache(); MeetupsRegistration existingMeetupsRegistration = _persistence.findByPrimaryKey(newMeetupsRegistration.getPrimaryKey()); Assert.assertEquals( Long.valueOf(existingMeetupsRegistration.getUserId()), ReflectionTestUtil.<Long>invoke( existingMeetupsRegistration, "getOriginalUserId", new Class<?>[0])); Assert.assertEquals( Long.valueOf(existingMeetupsRegistration.getMeetupsEntryId()), ReflectionTestUtil.<Long>invoke( existingMeetupsRegistration, "getOriginalMeetupsEntryId", new Class<?>[0])); }
@Test public void testResetOriginalValues() throws Exception { ServiceComponent newServiceComponent = addServiceComponent(); _persistence.clearCache(); ServiceComponent existingServiceComponent = _persistence.findByPrimaryKey(newServiceComponent.getPrimaryKey()); Assert.assertTrue( Validator.equals( existingServiceComponent.getBuildNamespace(), ReflectionTestUtil.invoke( existingServiceComponent, "getOriginalBuildNamespace", new Class<?>[0]))); Assert.assertEquals( Long.valueOf(existingServiceComponent.getBuildNumber()), ReflectionTestUtil.<Long>invoke( existingServiceComponent, "getOriginalBuildNumber", new Class<?>[0])); }
@Test public void testResetOriginalValues() throws Exception { DDLRecordVersion newDDLRecordVersion = addDDLRecordVersion(); _persistence.clearCache(); DDLRecordVersion existingDDLRecordVersion = _persistence.findByPrimaryKey(newDDLRecordVersion.getPrimaryKey()); Assert.assertEquals( Long.valueOf(existingDDLRecordVersion.getRecordId()), ReflectionTestUtil.<Long>invoke( existingDDLRecordVersion, "getOriginalRecordId", new Class<?>[0])); Assert.assertTrue( Validator.equals( existingDDLRecordVersion.getVersion(), ReflectionTestUtil.invoke( existingDDLRecordVersion, "getOriginalVersion", new Class<?>[0]))); }
@Test public void testResetOriginalValues() throws Exception { Status newStatus = addStatus(); _persistence.clearCache(); Status existingStatus = _persistence.findByPrimaryKey(newStatus.getPrimaryKey()); Assert.assertEquals( Long.valueOf(existingStatus.getUserId()), ReflectionTestUtil.<Long>invoke(existingStatus, "getOriginalUserId", new Class<?>[0])); }
@Test public void testResetOriginalValues() throws Exception { ShoppingOrder newShoppingOrder = addShoppingOrder(); _persistence.clearCache(); ShoppingOrder existingShoppingOrder = _persistence.findByPrimaryKey(newShoppingOrder.getPrimaryKey()); Assert.assertTrue( Objects.equals( existingShoppingOrder.getNumber(), ReflectionTestUtil.invoke( existingShoppingOrder, "getOriginalNumber", new Class<?>[0]))); Assert.assertTrue( Objects.equals( existingShoppingOrder.getPpTxnId(), ReflectionTestUtil.invoke( existingShoppingOrder, "getOriginalPpTxnId", new Class<?>[0]))); }
@Test public void testResetOriginalValues() throws Exception { RatingsEntry newRatingsEntry = addRatingsEntry(); _persistence.clearCache(); RatingsEntry existingRatingsEntry = _persistence.findByPrimaryKey(newRatingsEntry.getPrimaryKey()); Assert.assertEquals( Long.valueOf(existingRatingsEntry.getUserId()), ReflectionTestUtil.<Long>invoke( existingRatingsEntry, "getOriginalUserId", new Class<?>[0])); Assert.assertEquals( Long.valueOf(existingRatingsEntry.getClassNameId()), ReflectionTestUtil.<Long>invoke( existingRatingsEntry, "getOriginalClassNameId", new Class<?>[0])); Assert.assertEquals( Long.valueOf(existingRatingsEntry.getClassPK()), ReflectionTestUtil.<Long>invoke( existingRatingsEntry, "getOriginalClassPK", new Class<?>[0])); }
@Test public void testResetOriginalValues() throws Exception { Country newCountry = addCountry(); _persistence.clearCache(); Country existingCountry = _persistence.findByPrimaryKey(newCountry.getPrimaryKey()); Assert.assertTrue( Validator.equals( existingCountry.getName(), ReflectionTestUtil.invoke(existingCountry, "getOriginalName", new Class<?>[0]))); Assert.assertTrue( Validator.equals( existingCountry.getA2(), ReflectionTestUtil.invoke(existingCountry, "getOriginalA2", new Class<?>[0]))); Assert.assertTrue( Validator.equals( existingCountry.getA3(), ReflectionTestUtil.invoke(existingCountry, "getOriginalA3", new Class<?>[0]))); }
@Test public void testResetOriginalValues() throws Exception { MBMailingList newMBMailingList = addMBMailingList(); _persistence.clearCache(); MBMailingList existingMBMailingList = _persistence.findByPrimaryKey(newMBMailingList.getPrimaryKey()); Assert.assertTrue( Validator.equals( existingMBMailingList.getUuid(), ReflectionTestUtil.invoke(existingMBMailingList, "getOriginalUuid", new Class<?>[0]))); Assert.assertEquals( existingMBMailingList.getGroupId(), ReflectionTestUtil.invoke(existingMBMailingList, "getOriginalGroupId", new Class<?>[0])); Assert.assertEquals( existingMBMailingList.getGroupId(), ReflectionTestUtil.invoke(existingMBMailingList, "getOriginalGroupId", new Class<?>[0])); Assert.assertEquals( existingMBMailingList.getCategoryId(), ReflectionTestUtil.invoke(existingMBMailingList, "getOriginalCategoryId", new Class<?>[0])); }
@Test public void testResetOriginalValues() throws Exception { Team newTeam = addTeam(); _persistence.clearCache(); Team existingTeam = _persistence.findByPrimaryKey(newTeam.getPrimaryKey()); Assert.assertTrue( Objects.equals( existingTeam.getUuid(), ReflectionTestUtil.invoke(existingTeam, "getOriginalUuid", new Class<?>[0]))); Assert.assertEquals( Long.valueOf(existingTeam.getGroupId()), ReflectionTestUtil.<Long>invoke(existingTeam, "getOriginalGroupId", new Class<?>[0])); Assert.assertEquals( Long.valueOf(existingTeam.getGroupId()), ReflectionTestUtil.<Long>invoke(existingTeam, "getOriginalGroupId", new Class<?>[0])); Assert.assertTrue( Objects.equals( existingTeam.getName(), ReflectionTestUtil.invoke(existingTeam, "getOriginalName", new Class<?>[0]))); }
@AdviseWith(adviceClasses = {PropsUtilAdvice.class}) @NewEnv(type = NewEnv.Type.CLASSLOADER) @Test public void testPrepareRequest() throws Exception { PropsUtilAdvice.setProps( PropsKeys.INTRABAND_MAILBOX_REAPER_THREAD_ENABLED, Boolean.FALSE.toString()); PropsUtilAdvice.setProps( PropsKeys.INTRABAND_MAILBOX_STORAGE_LIFE, String.valueOf(Long.MAX_VALUE)); Serializer serializer = new Serializer(); serializer.writeString(_SERVLET_CONTEXT_NAME); serializer.writeObject(new SPIAgentRequest(_mockHttpServletRequest)); long receipt = ReflectionTestUtil.invoke( MailboxUtil.class, "depositMail", new Class<?>[] {ByteBuffer.class}, serializer.toByteBuffer()); byte[] data = new byte[8]; BigEndianCodec.putLong(data, 0, receipt); HttpClientSPIAgent httpClientSPIAgent = new HttpClientSPIAgent( _spiConfiguration, new MockRegistrationReference(new MockIntraband())); MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); mockHttpServletRequest.setContent(data); HttpServletRequest httpServletRequest = httpClientSPIAgent.prepareRequest(mockHttpServletRequest); Assert.assertNotNull(httpServletRequest.getAttribute(WebKeys.SPI_AGENT_REQUEST)); }
@Test public void testService() throws Exception { // Unable to borrow a socket HttpClientSPIAgent httpClientSPIAgent = new HttpClientSPIAgent( _spiConfiguration, new MockRegistrationReference(new MockIntraband())); try { httpClientSPIAgent.service(null, null); Assert.fail(); } catch (PortalResiliencyException pre) { Throwable throwable = pre.getCause(); Assert.assertSame(ConnectException.class, throwable.getClass()); } // Unable to send, successfully close MockIntraband mockIntraband = new MockIntraband(); IOException ioException = new IOException(); mockIntraband.setIOException(ioException); httpClientSPIAgent = new HttpClientSPIAgent(_spiConfiguration, new MockRegistrationReference(mockIntraband)); ServerSocketChannel serverSocketChannel = SocketUtil.createServerSocketChannel( InetAddressUtil.getLoopbackInetAddress(), _spiConfiguration.getConnectorPort(), null); serverSocketChannel.configureBlocking(true); SocketChannel socketChannel = SocketChannel.open(httpClientSPIAgent.socketAddress); Socket socket = socketChannel.socket(); Queue<Socket> socketBlockingQueue = httpClientSPIAgent.socketBlockingQueue; socketBlockingQueue.add(socket); MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); mockHttpServletRequest.setAttribute(WebKeys.SPI_AGENT_PORTLET, _portlet); try { httpClientSPIAgent.service(mockHttpServletRequest, null); Assert.fail(); } catch (PortalResiliencyException pre) { Throwable throwable = pre.getCause(); Assert.assertSame(IOException.class, throwable.getClass()); throwable = throwable.getCause(); Assert.assertSame(MailboxException.class, throwable.getClass()); Assert.assertSame(ioException, throwable.getCause()); } ServerSocket serverSocket = serverSocketChannel.socket(); closePeers(socket, serverSocket); CaptureHandler captureHandler = JDKLoggerTestUtil.configureJDKLogger(HttpClientSPIAgent.class.getName(), Level.OFF); try { // Unable to send, unable to close, without log List<LogRecord> logRecords = captureHandler.getLogRecords(); socket = new Socket( InetAddressUtil.getLoopbackInetAddress(), _spiConfiguration.getConnectorPort()); SocketImpl socketImpl = swapSocketImpl(socket, null); httpClientSPIAgent = new HttpClientSPIAgent(_spiConfiguration, new MockRegistrationReference(mockIntraband)); socketBlockingQueue = httpClientSPIAgent.socketBlockingQueue; socketBlockingQueue.add(socket); try { httpClientSPIAgent.service(mockHttpServletRequest, null); Assert.fail(); } catch (PortalResiliencyException pre) { Throwable throwable = pre.getCause(); Assert.assertSame(IOException.class, throwable.getClass()); } Assert.assertTrue(logRecords.isEmpty()); swapSocketImpl(socket, socketImpl); closePeers(socket, serverSocket); // Unable to send, unable to close, with log logRecords = captureHandler.resetLogLevel(Level.WARNING); socket = new Socket( InetAddressUtil.getLoopbackInetAddress(), _spiConfiguration.getConnectorPort()); socketImpl = swapSocketImpl(socket, null); httpClientSPIAgent = new HttpClientSPIAgent(_spiConfiguration, new MockRegistrationReference(mockIntraband)); socketBlockingQueue = httpClientSPIAgent.socketBlockingQueue; socketBlockingQueue.add(socket); try { httpClientSPIAgent.service(mockHttpServletRequest, null); Assert.fail(); } catch (PortalResiliencyException pre) { Throwable throwable = pre.getCause(); Assert.assertSame(IOException.class, throwable.getClass()); } Assert.assertEquals(1, logRecords.size()); LogRecord logRecord = logRecords.get(0); Throwable throwable = logRecord.getThrown(); Assert.assertSame(IOException.class, throwable.getClass()); swapSocketImpl(socket, socketImpl); } finally { captureHandler.close(); } closePeers(socket, serverSocket); // Successfully send socketChannel = SocketChannel.open(httpClientSPIAgent.socketAddress); socketChannel.configureBlocking(true); mockIntraband = new MockIntraband() { @Override protected Datagram processDatagram(Datagram datagram) { try { long receipt = ReflectionTestUtil.invoke( MailboxUtil.class, "depositMail", new Class<?>[] {ByteBuffer.class}, datagram.getDataByteBuffer()); byte[] receiptData = new byte[8]; BigEndianCodec.putLong(receiptData, 0, receipt); return Datagram.createResponseDatagram(datagram, ByteBuffer.wrap(receiptData)); } catch (Exception e) { throw new RuntimeException(e); } } }; httpClientSPIAgent = new HttpClientSPIAgent(_spiConfiguration, new MockRegistrationReference(mockIntraband)); socketBlockingQueue = httpClientSPIAgent.socketBlockingQueue; socket = socketChannel.socket(); socketBlockingQueue.add(socket); Serializer serializer = new Serializer(); serializer.writeString(_SERVLET_CONTEXT_NAME); serializer.writeObject(new SPIAgentResponse(_SERVLET_CONTEXT_NAME)); long receipt = ReflectionTestUtil.invoke( MailboxUtil.class, "depositMail", new Class<?>[] {ByteBuffer.class}, serializer.toByteBuffer()); Socket remoteSocket = serverSocket.accept(); OutputStream outputStream = remoteSocket.getOutputStream(); outputStream.write("HTTP/1.1 200 OK\n\n".getBytes("US-ASCII")); byte[] receiptData = new byte[8]; BigEndianCodec.putLong(receiptData, 0, receipt); outputStream.write(receiptData); outputStream.flush(); httpClientSPIAgent.service(mockHttpServletRequest, new MockHttpServletResponse()); socket.close(); remoteSocket.close(); serverSocket.close(); }
@Test public void testResetOriginalValues() throws Exception { DLFileEntry newDLFileEntry = addDLFileEntry(); _persistence.clearCache(); DLFileEntry existingDLFileEntry = _persistence.findByPrimaryKey(newDLFileEntry.getPrimaryKey()); Assert.assertTrue( Objects.equals( existingDLFileEntry.getUuid(), ReflectionTestUtil.invoke(existingDLFileEntry, "getOriginalUuid", new Class<?>[0]))); Assert.assertEquals( Long.valueOf(existingDLFileEntry.getGroupId()), ReflectionTestUtil.<Long>invoke( existingDLFileEntry, "getOriginalGroupId", new Class<?>[0])); Assert.assertEquals( Long.valueOf(existingDLFileEntry.getGroupId()), ReflectionTestUtil.<Long>invoke( existingDLFileEntry, "getOriginalGroupId", new Class<?>[0])); Assert.assertEquals( Long.valueOf(existingDLFileEntry.getFolderId()), ReflectionTestUtil.<Long>invoke( existingDLFileEntry, "getOriginalFolderId", new Class<?>[0])); Assert.assertTrue( Objects.equals( existingDLFileEntry.getName(), ReflectionTestUtil.invoke(existingDLFileEntry, "getOriginalName", new Class<?>[0]))); Assert.assertEquals( Long.valueOf(existingDLFileEntry.getGroupId()), ReflectionTestUtil.<Long>invoke( existingDLFileEntry, "getOriginalGroupId", new Class<?>[0])); Assert.assertEquals( Long.valueOf(existingDLFileEntry.getFolderId()), ReflectionTestUtil.<Long>invoke( existingDLFileEntry, "getOriginalFolderId", new Class<?>[0])); Assert.assertTrue( Objects.equals( existingDLFileEntry.getFileName(), ReflectionTestUtil.invoke( existingDLFileEntry, "getOriginalFileName", new Class<?>[0]))); Assert.assertEquals( Long.valueOf(existingDLFileEntry.getGroupId()), ReflectionTestUtil.<Long>invoke( existingDLFileEntry, "getOriginalGroupId", new Class<?>[0])); Assert.assertEquals( Long.valueOf(existingDLFileEntry.getFolderId()), ReflectionTestUtil.<Long>invoke( existingDLFileEntry, "getOriginalFolderId", new Class<?>[0])); Assert.assertTrue( Objects.equals( existingDLFileEntry.getTitle(), ReflectionTestUtil.invoke(existingDLFileEntry, "getOriginalTitle", new Class<?>[0]))); }