@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])));
  }
コード例 #3
0
  @Test
  public void testRenamedSystemKeys() throws Exception {
    String[][] originalRenamedSystemKeys =
        ReflectionTestUtil.getFieldValue(VerifyProperties.class, "_RENAMED_SYSTEM_KEYS");

    String renamedSystemKey = getFirstSystemPropertyKey();

    ReflectionTestUtil.setFieldValue(
        VerifyProperties.class,
        "_RENAMED_SYSTEM_KEYS",
        new String[][] {new String[] {renamedSystemKey, renamedSystemKey}});

    try (CaptureAppender captureAppender =
        Log4JLoggerTestUtil.configureLog4JLogger(VerifyProperties.class.getName(), Level.ERROR)) {

      doVerify();

      List<LoggingEvent> loggingEvents = captureAppender.getLoggingEvents();

      Assert.assertEquals(1, loggingEvents.size());

      LoggingEvent loggingEvent = loggingEvents.get(0);

      Assert.assertEquals(
          "System property \""
              + renamedSystemKey
              + "\" was renamed to \""
              + renamedSystemKey
              + "\"",
          loggingEvent.getMessage());
    } finally {
      ReflectionTestUtil.setFieldValue(
          VerifyProperties.class, "_RENAMED_SYSTEM_KEYS", originalRenamedSystemKeys);
    }
  }
コード例 #4
0
  @Test
  public void testObsoletePortalKeys() throws Exception {
    String[] originalObsoletePortalKeys =
        ReflectionTestUtil.getFieldValue(VerifyProperties.class, "_OBSOLETE_PORTAL_KEYS");

    String obsoletePortalKey = getFirstPortalPropertyKey();

    ReflectionTestUtil.setFieldValue(
        VerifyProperties.class, "_OBSOLETE_PORTAL_KEYS", new String[] {obsoletePortalKey});

    try (CaptureAppender captureAppender =
        Log4JLoggerTestUtil.configureLog4JLogger(VerifyProperties.class.getName(), Level.ERROR)) {

      doVerify();

      List<LoggingEvent> loggingEvents = captureAppender.getLoggingEvents();

      Assert.assertEquals(1, loggingEvents.size());

      LoggingEvent loggingEvent = loggingEvents.get(0);

      Assert.assertEquals(
          "Portal property \"" + obsoletePortalKey + "\" is obsolete", loggingEvent.getMessage());
    } finally {
      ReflectionTestUtil.setFieldValue(
          VerifyProperties.class, "_OBSOLETE_PORTAL_KEYS", originalObsoletePortalKeys);
    }
  }
コード例 #5
0
  @Test
  public void testMigratedPortalKeys() throws Exception {
    String[][] originalMigratedPortalKeys =
        ReflectionTestUtil.getFieldValue(VerifyProperties.class, "_MIGRATED_PORTAL_KEYS");

    String migratedPortalKey = getFirstPortalPropertyKey();

    ReflectionTestUtil.setFieldValue(
        VerifyProperties.class,
        "_MIGRATED_PORTAL_KEYS",
        new String[][] {new String[] {migratedPortalKey, migratedPortalKey}});

    try (CaptureAppender captureAppender =
        Log4JLoggerTestUtil.configureLog4JLogger(VerifyProperties.class.getName(), Level.ERROR)) {

      doVerify();

      List<LoggingEvent> loggingEvents = captureAppender.getLoggingEvents();

      Assert.assertEquals(1, loggingEvents.size());

      LoggingEvent loggingEvent = loggingEvents.get(0);

      Assert.assertEquals(
          "Portal property \""
              + migratedPortalKey
              + "\" was migrated to the system property \""
              + migratedPortalKey
              + "\"",
          loggingEvent.getMessage());
    } finally {
      ReflectionTestUtil.setFieldValue(
          VerifyProperties.class, "_MIGRATED_PORTAL_KEYS", originalMigratedPortalKeys);
    }
  }
コード例 #6
0
  @Before
  public void setUp() throws SchedulerException {
    Thread currentThread = Thread.currentThread();

    ClassLoader currentClassLoader = currentThread.getContextClassLoader();

    PortalClassLoaderUtil.setClassLoader(currentClassLoader);

    setUpPortalUUIDUtil();

    _quartzSchedulerEngine = new QuartzSchedulerEngine();

    _quartzSchedulerEngine.setJsonFactory(setUpJSONFactory());
    _quartzSchedulerEngine.setMessageBus(setUpMessageBus());
    _quartzSchedulerEngine.setPortletLocalService(setUpPortletLocalService());
    _quartzSchedulerEngine.setProps(setUpProps());
    _quartzSchedulerEngine.setQuartzTriggerFactory(_quartzTriggerFactory);

    ReflectionTestUtil.setFieldValue(
        _quartzSchedulerEngine,
        "_memoryScheduler",
        new MockScheduler(StorageType.MEMORY, _MEMORY_TEST_GROUP_NAME));

    ReflectionTestUtil.setFieldValue(
        _quartzSchedulerEngine,
        "_persistedScheduler",
        new MockScheduler(StorageType.PERSISTED, _PERSISTED_TEST_GROUP_NAME));

    _quartzSchedulerEngine.start();
  }
コード例 #7
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());
  }
コード例 #9
0
  @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]));
  }
コード例 #10
0
  protected void closeSocketChannel(SocketChannel socketChannel, FileDescriptor fileDescriptor)
      throws IOException {

    ReflectionTestUtil.setFieldValue(socketChannel, "fd", fileDescriptor);

    socketChannel.close();
  }
コード例 #11
0
  private static MPI _getMPIImpl() {
    MPI mpiImpl = ReflectionTestUtil.getFieldValue(MPIHelperUtil.class, "_mpiImpl");

    Assert.assertNotNull(mpiImpl);

    return mpiImpl;
  }
コード例 #12
0
  @AdviseWith(adviceClasses = {PropsUtilAdvice.class})
  @Test
  public void testShutdownFailWithoutLog() throws NoSuchObjectException {
    UnicastRemoteObject.unexportObject(_getMPIImpl(), true);

    final IOException ioException = new IOException();

    ReflectionTestUtil.setFieldValue(
        MPIHelperUtil.class,
        "_intraband",
        new MockIntraband() {

          @Override
          public void close() throws IOException {
            throw ioException;
          }
        });

    try (CaptureHandler captureHandler =
        JDKLoggerTestUtil.configureJDKLogger(MPIHelperUtil.class.getName(), Level.OFF)) {

      MPIHelperUtil.shutdown();

      List<LogRecord> logRecords = captureHandler.getLogRecords();

      Assert.assertTrue(logRecords.isEmpty());
    }
  }
コード例 #13
0
  @Test
  public void testInitJobState() throws Exception {
    List<SchedulerResponse> schedulerResponses =
        _quartzSchedulerEngine.getScheduledJobs(_PERSISTED_TEST_GROUP_NAME, StorageType.PERSISTED);

    Assert.assertEquals(_DEFAULT_JOB_NUMBER, schedulerResponses.size());

    MockScheduler mockScheduler =
        ReflectionTestUtil.getFieldValue(_quartzSchedulerEngine, "_persistedScheduler");

    mockScheduler.addJob(
        _TEST_JOB_NAME_PREFIX + "persisted",
        _PERSISTED_TEST_GROUP_NAME,
        StorageType.PERSISTED,
        null);

    schedulerResponses =
        _quartzSchedulerEngine.getScheduledJobs(_PERSISTED_TEST_GROUP_NAME, StorageType.PERSISTED);

    Assert.assertEquals(_DEFAULT_JOB_NUMBER + 1, schedulerResponses.size());

    _quartzSchedulerEngine.initJobState();

    schedulerResponses =
        _quartzSchedulerEngine.getScheduledJobs(_PERSISTED_TEST_GROUP_NAME, StorageType.PERSISTED);

    Assert.assertEquals(_DEFAULT_JOB_NUMBER, schedulerResponses.size());
  }
コード例 #14
0
  @Test
  public void testUpdate3() throws SchedulerException {
    MockScheduler mockScheduler =
        ReflectionTestUtil.getFieldValue(_quartzSchedulerEngine, "_memoryScheduler");

    String jobName = _TEST_JOB_NAME_PREFIX + "memory";

    mockScheduler.addJob(jobName, _MEMORY_TEST_GROUP_NAME, StorageType.MEMORY, null);

    SchedulerResponse schedulerResponse =
        _quartzSchedulerEngine.getScheduledJob(
            jobName, _MEMORY_TEST_GROUP_NAME, StorageType.MEMORY);

    Assert.assertNull(schedulerResponse.getTrigger());

    Trigger trigger =
        _quartzTriggerFactory.createTrigger(
            jobName, _MEMORY_TEST_GROUP_NAME, new Date(), null, _DEFAULT_INTERVAL, TimeUnit.SECOND);

    _quartzSchedulerEngine.update(trigger, StorageType.MEMORY);

    schedulerResponse =
        _quartzSchedulerEngine.getScheduledJob(
            _TEST_JOB_NAME_0, _MEMORY_TEST_GROUP_NAME, StorageType.MEMORY);

    Assert.assertNotNull(schedulerResponse.getTrigger());
  }
コード例 #15
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 {
    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]));
  }
コード例 #17
0
  @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 {
    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 {
    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]));
  }
  @Before
  public void setUp() throws Exception {
    _assetCategoryPersistence = AssetCategoryUtil.getPersistence();

    _sessionFactoryInvocationHandler =
        new SessionFactoryInvocationHandler(
            ReflectionTestUtil.getFieldValue(_assetCategoryPersistence, "_sessionFactory"));

    ReflectionTestUtil.setFieldValue(
        _assetCategoryPersistence,
        "_sessionFactory",
        ProxyUtil.newProxyInstance(
            SessionFactory.class.getClassLoader(),
            new Class<?>[] {SessionFactory.class},
            _sessionFactoryInvocationHandler));

    _assetCategoryPersistence.setRebuildTreeEnabled(false);

    _nestedSetsTreeManager =
        new PersistenceNestedSetsTreeManager<AssetCategory>(
            (BasePersistenceImpl<?>) _assetCategoryPersistence,
            "AssetCategory",
            "AssetCategory",
            AssetCategoryImpl.class,
            "categoryId",
            "groupId",
            "leftCategoryId",
            "rightCategoryId");

    _group = GroupTestUtil.addGroup();

    _assetVocabulary = AssetTestUtil.addVocabulary(_group.getGroupId());

    _assetCategories = new AssetCategory[9];

    for (int i = 0; i < 9; i++) {
      _assetCategories[i] =
          AssetTestUtil.addCategory(_group.getGroupId(), _assetVocabulary.getVocabularyId());
    }

    PropsValues.SPRING_HIBERNATE_SESSION_DELEGATED = false;
  }
コード例 #21
0
  @Test
  public void testAutoRemoveFileInputStream() throws Exception {
    File tempFile = new File("tempFile");

    Assert.assertTrue(tempFile.createNewFile());

    AutoDeleteFileInputStream autoRemoveFileInputStream = new AutoDeleteFileInputStream(tempFile);

    final AtomicInteger checkDeleteCount = new AtomicInteger();

    SwappableSecurityManager swappableSecurityManager =
        new SwappableSecurityManager() {

          @Override
          public void checkDelete(String file) {
            if (file.contains("tempFile")) {
              checkDeleteCount.getAndIncrement();
            }
          }
        };

    try (SwappableSecurityManager autoCloseSwappableSecurityManager = swappableSecurityManager) {

      autoCloseSwappableSecurityManager.install();

      autoRemoveFileInputStream.close();
    }

    Assert.assertFalse(tempFile.exists());
    Assert.assertEquals(1, checkDeleteCount.get());

    checkDeleteCount.set(0);

    Assert.assertTrue(tempFile.createNewFile());

    autoRemoveFileInputStream = new AutoDeleteFileInputStream(tempFile);

    Assert.assertTrue(tempFile.delete());

    try (SwappableSecurityManager autoCloseSwappableSecurityManager = swappableSecurityManager) {

      autoCloseSwappableSecurityManager.install();

      autoRemoveFileInputStream.close();
    }

    Assert.assertFalse(tempFile.exists());
    Assert.assertEquals(2, checkDeleteCount.get());

    Set<String> files =
        ReflectionTestUtil.getFieldValue(Class.forName("java.io.DeleteOnExitHook"), "files");

    Assert.assertTrue(files.contains(tempFile.getPath()));
  }
コード例 #22
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])));
  }
コード例 #23
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]));
  }
コード例 #24
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]));
  }
コード例 #25
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])));
  }
コード例 #26
0
  protected SocketImpl swapSocketImpl(Socket socket, SocketImpl socketImpl) {
    SocketImpl oldSocketImpl = ReflectionTestUtil.getFieldValue(socket, "impl");

    if (socketImpl == null) {
      Socket unbindSocket = new Socket();

      socketImpl = ReflectionTestUtil.getFieldValue(unbindSocket, "impl");

      ReflectionTestUtil.setFieldValue(
          socketImpl,
          "cmdsock",
          new Socket() {

            @Override
            public synchronized void close() throws IOException {
              throw new IOException();
            }
          });
    }

    ReflectionTestUtil.setFieldValue(socket, "impl", socketImpl);

    return oldSocketImpl;
  }
コード例 #27
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])));
  }
コード例 #28
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]));
  }
コード例 #29
0
  @AdviseWith(adviceClasses = {PropsUtilAdvice.class})
  @Test
  public void testShutdownFailWithLog() throws NoSuchObjectException {
    UnicastRemoteObject.unexportObject(_getMPIImpl(), true);

    final IOException ioException = new IOException();

    ReflectionTestUtil.setFieldValue(
        MPIHelperUtil.class,
        "_intraband",
        new MockIntraband() {

          @Override
          public void close() throws IOException {
            throw ioException;
          }
        });

    try (CaptureHandler captureHandler =
        JDKLoggerTestUtil.configureJDKLogger(MPIHelperUtil.class.getName(), Level.WARNING)) {

      MPIHelperUtil.shutdown();

      List<LogRecord> logRecords = captureHandler.getLogRecords();

      Assert.assertEquals(2, logRecords.size());

      LogRecord logRecord = logRecords.get(0);

      logRecord = logRecords.get(0);

      Assert.assertEquals("Unable to unexport " + _getMPIImpl(), logRecord.getMessage());

      Throwable throwable = logRecord.getThrown();

      Assert.assertSame(NoSuchObjectException.class, throwable.getClass());

      logRecord = logRecords.get(1);

      Assert.assertEquals("Unable to close intraband", logRecord.getMessage());
      Assert.assertSame(ioException, logRecord.getThrown());
    }
  }
コード例 #30
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));
  }