@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);
    }
  }
  @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();
  }
  @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);
    }
  }
  @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);
    }
  }
  protected void closeSocketChannel(SocketChannel socketChannel, FileDescriptor fileDescriptor)
      throws IOException {

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

    socketChannel.close();
  }
Exemplo n.º 6
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());
    }
  }
  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;
  }
Exemplo n.º 8
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());
    }
  }
  @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;
  }
Exemplo n.º 10
0
  @Test
  public void testBaseSeleniumTestCaseSpringConfigs() {
    String log4jConfigureOnStartup = SystemProperties.get(_LOG4J_CONFIGURE_ON_STARTUP);

    SystemProperties.set(_LOG4J_CONFIGURE_ON_STARTUP, StringPool.FALSE);

    String resourceActionsReadPortletResources =
        SystemProperties.get(_RESOURCE_ACTIONS_READ_PORTLET_RESOURCES);

    SystemProperties.set(_RESOURCE_ACTIONS_READ_PORTLET_RESOURCES, StringPool.FALSE);

    ReflectionTestUtil.setFieldValue(
        PropsValues.class, "SPRING_INFRASTRUCTURE_CONFIGS", new String[0]);

    _fileImpl.deltree(PropsValues.MODULE_FRAMEWORK_STATE_DIR);

    try {
      InitUtil.initWithSpring(Arrays.asList("META-INF/util-spring.xml"), true);
    } finally {
      if (resourceActionsReadPortletResources == null) {
        SystemProperties.clear(_RESOURCE_ACTIONS_READ_PORTLET_RESOURCES);
      } else {
        SystemProperties.set(
            _RESOURCE_ACTIONS_READ_PORTLET_RESOURCES, resourceActionsReadPortletResources);
      }

      if (log4jConfigureOnStartup == null) {
        SystemProperties.clear(_LOG4J_CONFIGURE_ON_STARTUP);
      } else {
        SystemProperties.set(_LOG4J_CONFIGURE_ON_STARTUP, log4jConfigureOnStartup);
      }

      InitUtil.stopRuntime();

      InitUtil.stopModuleFramework();
    }
  }
Exemplo n.º 11
0
  @AdviseWith(adviceClasses = {PropsUtilAdvice.class})
  @Test
  public void testSPIProviderRegistration() throws RemoteException {

    // Register SPI provider, null name

    MockSPIProvider mockSPIProvider1 = new MockSPIProvider(null);

    try {
      MPIHelperUtil.registerSPIProvider(mockSPIProvider1);

      Assert.fail();
    } catch (NullPointerException npe) {
    }

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

      // Register SPI provider, with log

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

      String name1 = "spiProvider1";

      mockSPIProvider1 = new MockSPIProvider(name1);

      Assert.assertTrue(MPIHelperUtil.registerSPIProvider(mockSPIProvider1));
      Assert.assertEquals(1, logRecords.size());

      LogRecord logRecord1 = logRecords.get(0);

      Assert.assertEquals("Registered SPI provider " + mockSPIProvider1, logRecord1.getMessage());

      // Register SPI provider, without log

      logRecords = captureHandler.resetLogLevel(Level.OFF);

      String name2 = "spiProvider2";

      MockSPIProvider mockSPIProvider2 = new MockSPIProvider(name2);

      Assert.assertTrue(MPIHelperUtil.registerSPIProvider(mockSPIProvider2));
      Assert.assertTrue(logRecords.isEmpty());

      // Register SPI provider, duplicate name, with log

      logRecords = captureHandler.resetLogLevel(Level.WARNING);

      MockSPIProvider mockSPIProvider3 = new MockSPIProvider(name1);

      Assert.assertFalse(MPIHelperUtil.registerSPIProvider(mockSPIProvider3));
      Assert.assertEquals(1, logRecords.size());

      logRecord1 = logRecords.get(0);

      Assert.assertEquals(
          "Not registering SPI provider "
              + mockSPIProvider3
              + " because it duplicates "
              + mockSPIProvider1,
          logRecord1.getMessage());

      // Register SPI provider, duplicate name, without log

      logRecords = captureHandler.resetLogLevel(Level.OFF);

      mockSPIProvider3 = new MockSPIProvider(name1);

      Assert.assertFalse(MPIHelperUtil.registerSPIProvider(mockSPIProvider3));
      Assert.assertTrue(logRecords.isEmpty());

      // Get SPI provider

      String name3 = "spiProvider3";

      Assert.assertSame(mockSPIProvider1, MPIHelperUtil.getSPIProvider(name1));
      Assert.assertSame(mockSPIProvider2, MPIHelperUtil.getSPIProvider(name2));
      Assert.assertNull(MPIHelperUtil.getSPIProvider(name3));

      List<SPIProvider> spiProviders = MPIHelperUtil.getSPIProviders();

      Assert.assertEquals(2, spiProviders.size());
      Assert.assertTrue(spiProviders.contains(mockSPIProvider1));
      Assert.assertTrue(spiProviders.contains(mockSPIProvider2));

      // Unregister SPI provider, null name

      mockSPIProvider3 = new MockSPIProvider(null);

      try {
        MPIHelperUtil.unregisterSPIProvider(mockSPIProvider3);

        Assert.fail();
      } catch (NullPointerException npe) {
      }

      // Unregister SPI provider, nonexistent name, with log

      logRecords = captureHandler.resetLogLevel(Level.WARNING);

      mockSPIProvider3 = new MockSPIProvider(name3);

      Assert.assertFalse(MPIHelperUtil.unregisterSPIProvider(mockSPIProvider3));
      Assert.assertEquals(1, logRecords.size());

      logRecord1 = logRecords.get(0);

      Assert.assertEquals(
          "Not unregistering unregistered SPI provider " + mockSPIProvider3,
          logRecord1.getMessage());

      // Unregister SPI provider, nonexistent name, without log

      logRecords = captureHandler.resetLogLevel(Level.OFF);

      mockSPIProvider3 = new MockSPIProvider(name3);

      Assert.assertFalse(MPIHelperUtil.unregisterSPIProvider(mockSPIProvider3));
      Assert.assertTrue(logRecords.isEmpty());

      // Unregister SPI provider, mismatch instance, with log

      logRecords = captureHandler.resetLogLevel(Level.INFO);

      Assert.assertFalse(MPIHelperUtil.unregisterSPIProvider(new MockSPIProvider(name2)));
      Assert.assertEquals(1, logRecords.size());

      logRecord1 = logRecords.get(0);

      Assert.assertEquals(
          "Not unregistering unregistered SPI provider " + name2, logRecord1.getMessage());

      // Unregister SPI provider, mismatch instance, without log

      logRecords = captureHandler.resetLogLevel(Level.OFF);

      Assert.assertFalse(MPIHelperUtil.unregisterSPIProvider(new MockSPIProvider(name2)));
      Assert.assertTrue(logRecords.isEmpty());

      // Unregister SPI provider, concurrent remove failure, with log

      logRecords = captureHandler.resetLogLevel(Level.INFO);

      ConcurrentMap<String, Object> oldSPIProviderContainers =
          ReflectionTestUtil.getFieldValue(MPIHelperUtil.class, "_spiProviderContainers");

      try {
        ReflectionTestUtil.setFieldValue(
            MPIHelperUtil.class,
            "_spiProviderContainers",
            new ConcurrentHashMap<String, Object>(oldSPIProviderContainers) {

              @Override
              public boolean remove(Object key, Object value) {
                return false;
              }
            });

        Assert.assertFalse(MPIHelperUtil.unregisterSPIProvider(mockSPIProvider2));
      } finally {
        ReflectionTestUtil.setFieldValue(
            MPIHelperUtil.class, "_spiProviderContainers", oldSPIProviderContainers);
      }

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

      logRecord1 = logRecords.get(0);

      Assert.assertEquals(
          "Not unregistering unregistered SPI provider " + name2, logRecord1.getMessage());

      // Unregister SPI provider, concurrent remove failure, without log

      logRecords = captureHandler.resetLogLevel(Level.OFF);

      oldSPIProviderContainers =
          ReflectionTestUtil.getFieldValue(MPIHelperUtil.class, "_spiProviderContainers");

      try {
        ReflectionTestUtil.setFieldValue(
            MPIHelperUtil.class,
            "_spiProviderContainers",
            new ConcurrentHashMap<String, Object>(oldSPIProviderContainers) {

              @Override
              public boolean remove(Object key, Object value) {
                return false;
              }
            });

        Assert.assertFalse(MPIHelperUtil.unregisterSPIProvider(mockSPIProvider2));
      } finally {
        ReflectionTestUtil.setFieldValue(
            MPIHelperUtil.class, "_spiProviderContainers", oldSPIProviderContainers);
      }

      Assert.assertTrue(logRecords.isEmpty());

      // Unregister SPI provider, with no SPI, with log

      logRecords = captureHandler.resetLogLevel(Level.INFO);

      Assert.assertTrue(MPIHelperUtil.unregisterSPIProvider(mockSPIProvider2));
      Assert.assertEquals(1, logRecords.size());

      logRecord1 = logRecords.get(0);

      Assert.assertEquals("Unregistered SPI provider " + mockSPIProvider2, logRecord1.getMessage());

      // Unregister SPI provider, with no SPI, without log

      logRecords = captureHandler.resetLogLevel(Level.OFF);

      Assert.assertTrue(MPIHelperUtil.unregisterSPIProvider(mockSPIProvider1));
      Assert.assertTrue(logRecords.isEmpty());

      // Unregister SPI provider, with SPI, fail on stop, with log

      logRecords = captureHandler.resetLogLevel(Level.SEVERE);

      mockSPIProvider1 = new MockSPIProvider(name1);

      Assert.assertTrue(MPIHelperUtil.registerSPIProvider(mockSPIProvider1));

      mockSPIProvider2 = new MockSPIProvider(name2);

      Assert.assertTrue(MPIHelperUtil.registerSPIProvider(mockSPIProvider2));

      MockSPI mockSPI1 = new MockSPI();

      mockSPI1.failOnStop = true;
      mockSPI1.spiProviderName = name1;

      MPIHelperUtilTestUtil.directResigterSPI("spi1", mockSPI1);

      MockSPI mockSPI2 = new MockSPI();

      mockSPI2.failOnStop = true;
      mockSPI2.spiProviderName = name2;

      MPIHelperUtilTestUtil.directResigterSPI("spi2", mockSPI2);

      Assert.assertTrue(MPIHelperUtil.unregisterSPIProvider(mockSPIProvider1));
      Assert.assertFalse(mockSPI1.destroyed);
      Assert.assertFalse(mockSPI1.stopped);
      Assert.assertFalse(mockSPI2.destroyed);
      Assert.assertFalse(mockSPI2.stopped);
      Assert.assertEquals(1, logRecords.size());

      logRecord1 = logRecords.get(0);

      Assert.assertEquals(
          "Unable to unregister SPI "
              + mockSPI1
              + " while unregistering SPI provider "
              + mockSPIProvider1,
          logRecord1.getMessage());

      Throwable throwable = logRecord1.getThrown();

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

      // Unregister SPI provider, with SPI, fail on destroy, without log

      logRecords = captureHandler.resetLogLevel(Level.OFF);

      mockSPI1.failOnDestroy = true;
      mockSPI1.failOnStop = false;

      mockSPI2.failOnDestroy = true;
      mockSPI2.failOnStop = false;

      Assert.assertTrue(MPIHelperUtil.unregisterSPIProvider(mockSPIProvider2));
      Assert.assertFalse(mockSPI1.destroyed);
      Assert.assertFalse(mockSPI1.stopped);
      Assert.assertFalse(mockSPI2.destroyed);
      Assert.assertTrue(mockSPI2.stopped);
      Assert.assertTrue(logRecords.isEmpty());

      // Unregister SPI provider, with SPI, fail on catch, without log

      logRecords = captureHandler.resetLogLevel(Level.OFF);

      mockSPIProvider1 = new MockSPIProvider(name1);

      Assert.assertTrue(MPIHelperUtil.registerSPIProvider(mockSPIProvider1));

      final RuntimeException runtimeException = new RuntimeException();

      mockSPI1 =
          new MockSPI() {

            @Override
            public String toString() {
              throw runtimeException;
            }
          };

      mockSPI1.failOnDestroy = true;
      mockSPI1.failOnStop = false;
      mockSPI1.spiProviderName = name1;

      MPIHelperUtilTestUtil.directResigterSPI(name1, mockSPI1);

      try {
        MPIHelperUtil.unregisterSPIProvider(mockSPIProvider1);

        Assert.fail();
      } catch (RuntimeException re) {
        Assert.assertSame(runtimeException, re);
      }

      Assert.assertTrue(logRecords.isEmpty());

      // Unregister SPI provider, with SPI, success, with log

      mockSPIProvider1 = new MockSPIProvider(name1);

      Assert.assertTrue(MPIHelperUtil.registerSPIProvider(mockSPIProvider1));

      mockSPIProvider2 = new MockSPIProvider(name2);

      Assert.assertTrue(MPIHelperUtil.registerSPIProvider(mockSPIProvider2));

      mockSPI1 = new MockSPI();

      mockSPI1.failOnDestroy = false;
      mockSPI1.spiProviderName = name1;

      MPIHelperUtilTestUtil.directResigterSPI("spi1", mockSPI1);

      mockSPI2 = new MockSPI();

      mockSPI2.failOnDestroy = false;
      mockSPI2.spiProviderName = name2;

      MPIHelperUtilTestUtil.directResigterSPI("spi2", mockSPI2);

      logRecords = captureHandler.resetLogLevel(Level.INFO);

      Assert.assertTrue(MPIHelperUtil.unregisterSPIProvider(mockSPIProvider1));
      Assert.assertTrue(mockSPI1.destroyed);
      Assert.assertTrue(mockSPI1.stopped);
      Assert.assertFalse(mockSPI2.destroyed);
      Assert.assertFalse(mockSPI2.stopped);
      Assert.assertEquals(2, logRecords.size());

      logRecord1 = logRecords.get(0);

      Assert.assertEquals(
          "Unregistered SPI " + mockSPI1 + " while unregistering SPI provider " + mockSPIProvider1,
          logRecord1.getMessage());

      LogRecord logRecord2 = logRecords.get(1);

      Assert.assertEquals("Unregistered SPI provider " + mockSPIProvider1, logRecord2.getMessage());

      // Unregister SPI provider, with SPI, success, without log

      logRecords = captureHandler.resetLogLevel(Level.OFF);

      Assert.assertTrue(MPIHelperUtil.unregisterSPIProvider(mockSPIProvider2));
      Assert.assertTrue(mockSPI1.destroyed);
      Assert.assertTrue(mockSPI1.stopped);
      Assert.assertTrue(mockSPI2.destroyed);
      Assert.assertTrue(mockSPI2.stopped);
      Assert.assertTrue(logRecords.isEmpty());
    }
  }