Example #1
0
  @Override
  public void contextInitialized(ServletContextEvent se) {
    String logFileName = se.getServletContext().getInitParameter("log4jFileName");
    String env = System.getenv("env");

    String confFileName;
    if (env == null) {
      confFileName = se.getServletContext().getInitParameter("configFileName");
    } else {
      confFileName = "/" + env + ".properties";
    }

    if (logFileName != null) {
      InputStream in = getClass().getResourceAsStream(logFileName);
      if (in == null) {
        in = ClassLoader.getSystemResourceAsStream(logFileName);
      }
      try {
        PropertyConfigurator.configure(in);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    if (confFileName != null) {
      PropertyLoader.getInstance().init(confFileName);
    }
  }
  @org.junit.Test(expected = PropertyLoaderException.class)
  public void
      testLoadPropertiesFromBaseNameList_Calls_PropertyFileReader_And_Prevents_StackOverflow() {
    Stack<String> fileNameStack = new Stack<String>();
    when(propertyLoaderFactory.getEmptyProperties()).thenReturn(properties);
    when(propertyLoaderFactory.getEmptyFileNameStack()).thenReturn(fileNameStack);
    when(propertyLoaderFactory.getStringBuilder()).thenReturn(new StringBuilder());
    List<String> fileNames = Arrays.asList("file1.properties", "file2.properties");
    ArrayList<String> suffixes = new ArrayList<String>();
    when(propertySuffix.getSuffixes()).thenReturn(suffixes);
    when(propertyFileNameHelper.getFileNames(
            Matchers.anyCollection(), Matchers.anyCollection(), Matchers.anyString()))
        .thenReturn(fileNames);
    when(propertyLocation.getOpeners())
        .thenReturn(
            Arrays.<PropertyLoaderOpener>asList(propertyLoaderOpener1, propertyLoaderOpener2));
    when(propertyFileReader.tryToReadPropertiesFromFile(
            Matchers.anyString(), Matchers.anyString(), Matchers.any(PropertyLoaderOpener.class)))
        .thenReturn(properties);

    propertyLoader.load();

    verify(propertyFileReader)
        .tryToReadPropertiesFromFile("file1.properties", "ISO-8859-1", propertyLoaderOpener1);
    verify(propertyFileReader)
        .tryToReadPropertiesFromFile("file2.properties", "ISO-8859-1", propertyLoaderOpener1);
    verify(propertyFileReader)
        .tryToReadPropertiesFromFile("file1.properties", "ISO-8859-1", propertyLoaderOpener2);
    verify(propertyFileReader)
        .tryToReadPropertiesFromFile("file2.properties", "ISO-8859-1", propertyLoaderOpener2);
    verify(properties, times(4)).putAll(properties);
  }
  @Override
  public Map<QName, List<String>> getClaimedAttributes(
      Subject subject, String appliesTo, String tokenType, Claims claims) {
    String name = null;

    Set<Principal> principals = subject.getPrincipals();
    if (principals != null) {
      final Iterator<Principal> iterator = principals.iterator();
      while (iterator.hasNext()) {
        String cnName = principals.iterator().next().getName();
        int pos = cnName.indexOf("=");
        name = cnName.substring(pos + 1);
        break;
      }
    }

    Map<QName, List<String>> attributes = new HashMap<QName, List<String>>();

    addAttribute(attributes, STSAttributeProvider.NAME_IDENTIFIER, name);
    addAttribute(attributes, "dummy_id1", "test_dummy_attribute1");
    addAttribute(attributes, "userid", name);
    addAttribute(attributes, "dummy_id2", "test_dummy_attribute2");

    String tenantId =
        PropertyLoader.getInstance().load(COMMON_PROPERTIES_PATH).getProperty(TENANT_ID);

    addAttribute(attributes, TENANT_ID, tenantId);
    // claims not considered here

    return attributes;
  }
Example #4
0
  /*
   * Creates a table with the following attributes:
   *
   * Table name: testTableName Hash key: userNo type N Read Capacity Units: 10
   * Write Capacity Units: 5
   */
  public static void createTable() {

    /*AmazonDynamoDBClient ddb = UserPreferenceDemoActivity.clientManager
    .ddb();*/
    AmazonDynamoDBClient ddb = LoginActivity.clientManager.ddb();
    KeySchemaElement kse =
        new KeySchemaElement().withAttributeName("userNo").withKeyType(KeyType.HASH);
    AttributeDefinition ad =
        new AttributeDefinition()
            .withAttributeName("userNo")
            .withAttributeType(ScalarAttributeType.N);
    ProvisionedThroughput pt =
        new ProvisionedThroughput().withReadCapacityUnits(10l).withWriteCapacityUnits(5l);

    CreateTableRequest request =
        new CreateTableRequest()
            .withTableName(PropertyLoader.getInstance().getTestTableName())
            .withKeySchema(kse)
            .withAttributeDefinitions(ad)
            .withProvisionedThroughput(pt);

    try {
      ddb.createTable(request);
    } catch (AmazonServiceException ex) {
      /*UserPreferenceDemoActivity.clientManager
      .wipeCredentialsOnAuthError(ex);*/
      LoginActivity.clientManager.wipeCredentialsOnAuthError(ex);
    }
  }
 @Test
 public void testLoad_Calls_loadPropertiesFromBaseNameList_And_filterProperties()
     throws Exception {
   propertyLoader.load();
   verify(propertyLoaderFactory).getEmptyFileNameStack();
   verify(propertyLoaderFactory).getEmptyProperties();
   verify(propertyFilter).getFilters();
 }
 public static void parseProvider(String provider) {
   doc.getDocumentElement().normalize();
   if (PropertyLoader.loadProperty("env").contains(".com")) {
     String prodProvider = provider + "_prod";
     nList = doc.getElementsByTagName(prodProvider);
   } else {
     nList = doc.getElementsByTagName(provider);
   }
   System.out.println("----------testData------------------");
 }
Example #7
0
  /*
   * Deletes the test table and all of its users and their attribute/value
   * pairs.
   */
  public static void cleanUp() {

    AmazonDynamoDBClient ddb = LoginActivity.clientManager.ddb();

    DeleteTableRequest request =
        new DeleteTableRequest().withTableName(PropertyLoader.getInstance().getTestTableName());
    try {
      ddb.deleteTable(request);

    } catch (AmazonServiceException ex) {
      LoginActivity.clientManager.wipeCredentialsOnAuthError(ex);
    }
  }
  @Test
  public void testWithDefaultConfig() throws Exception {

    when(propertyLocation.clear()).thenReturn(propertyLocation);
    when(propertySuffix.clear()).thenReturn(propertySuffix);
    when(propertyFilter.clear()).thenReturn(propertyFilter);

    assertEquals(propertyLoader, propertyLoader.withDefaultConfig());

    verify(propertyLocation).clear();
    verify(propertySuffix).clear();
    verify(propertyFilter).clear();
    verify(propertyLocation).atDefaultLocations();
    verify(propertySuffix).addDefaultSuffixes();
    verify(propertyFilter).withDefaultFilters();
  }
Example #9
0
  /*
   * Retrieves the table description and returns the table status as a string.
   */
  public static String getTestTableStatus() {

    try {
      /*AmazonDynamoDBClient ddb = UserPreferenceDemoActivity.clientManager
      .ddb();*/
      AmazonDynamoDBClient ddb = LoginActivity.clientManager.ddb();
      DescribeTableRequest request =
          new DescribeTableRequest().withTableName(PropertyLoader.getInstance().getTestTableName());
      DescribeTableResult result = ddb.describeTable(request);

      String status = result.getTable().getTableStatus();
      return status == null ? "" : status;

    } catch (ResourceNotFoundException e) {
    } catch (AmazonServiceException ex) {
      LoginActivity.clientManager.wipeCredentialsOnAuthError(ex);
    }

    return "";
  }
 @Test
 public void testWithWarnIfPropertyHasToBeDefined() throws Exception {
   assertEquals(propertyLoader, propertyLoader.withWarnIfPropertyHasToBeDefined());
   verify(propertyFilter).withWarnIfPropertyHasToBeDefined();
 }
 @Test
 public void testAtRelativeToClass() throws Exception {
   assertEquals(propertyLoader, propertyLoader.atRelativeToClass(this.getClass()));
   verify(propertyLocation).atRelativeToClass(this.getClass());
 }
 @Test
 public void testAtContextClassPath() throws Exception {
   assertEquals(propertyLoader, propertyLoader.atContextClassPath());
   verify(propertyLocation).atContextClassPath();
 }
 @Test
 public void testAtBaseURL() throws Exception {
   URL url = new File("").toURI().toURL();
   assertEquals(propertyLoader, propertyLoader.atBaseURL(url));
   verify(propertyLocation).atBaseURL(url);
 }
 @Test
 public void testFromClassLoader() throws Exception {
   assertEquals(propertyLoader, propertyLoader.atClassLoader(this.getClass().getClassLoader()));
   verify(propertyLocation).atClassLoader(this.getClass().getClassLoader());
 }
 @Test
 public void testGetFilters() throws Exception {
   assertEquals(propertyFilter, propertyLoader.getFilters());
 }
 @Test
 public void testGetExtension() throws Exception {
   assertEquals("properties", propertyLoader.getExtension());
 }
 @Test
 public void testGetLocations() throws Exception {
   assertEquals(propertyLocation, propertyLoader.getLocations());
 }
 @Test
 public void testGetSuffixes() throws Exception {
   assertEquals(propertySuffix, propertyLoader.getSuffixes());
 }
 @Test
 public void testAddString() throws Exception {
   assertEquals(propertyLoader, propertyLoader.addString("suf"));
   verify(propertySuffix).addString("suf");
 }
 @Test
 public void testAddLocalHostNames() throws Exception {
   assertEquals(propertyLoader, propertyLoader.addLocalHostNames());
   verify(propertySuffix).addLocalHostNames();
 }
 @Test
 public void testAtDirectory() throws Exception {
   assertEquals(propertyLoader, propertyLoader.atDirectory("dir"));
   verify(propertyLocation).atDirectory("dir");
 }
 @Test
 public void testAddSuffixList() throws Exception {
   List<String> suf = new ArrayList<String>();
   assertEquals(propertyLoader, propertyLoader.addSuffixList(suf));
   verify(propertySuffix).addSuffixList(suf);
 }
 @Test
 public void testWithEnvironmentResolvingFilter() throws Exception {
   assertEquals(propertyLoader, propertyLoader.withEnvironmentResolvingFilter());
   verify(propertyFilter).withEnvironmentResolvingFilter();
 }
 @Test
 public void testWithDefaultFilters() throws Exception {
   assertEquals(propertyLoader, propertyLoader.withDefaultFilters());
   verify(propertyFilter).withDefaultFilters();
 }
 @Test
 public void testAddDefaultSuffixes() throws Exception {
   assertEquals(propertyLoader, propertyLoader.addDefaultSuffixes());
   verify(propertySuffix).addDefaultSuffixes();
 }
 @Test
 public void testWithWarnOnSurroundingWhitespace() throws Exception {
   assertEquals(propertyLoader, propertyLoader.withWarnOnSurroundingWhitespace());
   verify(propertyFilter).withWarnOnSurroundingWhitespace();
 }
 @Test
 public void testAtDefaultLocations() throws Exception {
   assertEquals(propertyLoader, propertyLoader.atDefaultLocations());
   verify(propertyLocation).atDefaultLocations();
 }