[
https://issues.apache.org/jira/browse/STORM-1233?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15184204#comment-15184204
]
ASF GitHub Bot commented on STORM-1233:
---------------------------------------
Github user hustfxj commented on a diff in the pull request:
https://github.com/apache/storm/pull/1191#discussion_r55305746
--- Diff:
storm-core/test/jvm/org/apache/storm/security/auth/AuthUtilsTest.java ---
@@ -0,0 +1,227 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.storm.security.auth;
+
+import java.io.IOException;
+import java.io.File;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.security.auth.login.AppConfigurationEntry;
+import javax.security.auth.login.Configuration;
+import javax.security.auth.Subject;
+
+import org.apache.commons.codec.binary.Hex;
+import org.apache.storm.Config;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.rules.TemporaryFolder;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class AuthUtilsTest {
+
+ @Test(expected=IOException.class)
+ public void getOptionsThrowsOnMissingSectionTest() throws IOException {
+ Configuration mockConfig = Mockito.mock(Configuration.class);
+ AuthUtils.get(mockConfig, "bogus-section", "");
+ }
+
+ @Test
+ public void getNonExistentSectionTest() throws IOException {
+ Map<String, String> optionMap = new HashMap<String, String>();
+ AppConfigurationEntry entry =
Mockito.mock(AppConfigurationEntry.class);
+
+ Mockito.<Map<String,
?>>when(entry.getOptions()).thenReturn(optionMap);
+ String section = "bogus-section";
+ Configuration mockConfig = Mockito.mock(Configuration.class);
+ Mockito.when(mockConfig.getAppConfigurationEntry(section))
+ .thenReturn(new AppConfigurationEntry[] {entry});
+ Assert.assertNull(
+ AuthUtils.get(mockConfig, section, "nonexistent-key"));
+ }
+
+ @Test
+ public void getFirstValueForValidKeyTest() throws IOException {
+ Map<String, String> optionMap = new HashMap<String, String>();
+ optionMap.put("existent-key", "foo");
+ AppConfigurationEntry entry =
Mockito.mock(AppConfigurationEntry.class);
+
+ Mockito.<Map<String,
?>>when(entry.getOptions()).thenReturn(optionMap);
+ String section = "bogus-section";
+ Configuration mockConfig = Mockito.mock(Configuration.class);
+ Mockito.when(mockConfig.getAppConfigurationEntry(section))
+ .thenReturn(new AppConfigurationEntry[] {entry});
+ Assert.assertEquals(
+ AuthUtils.get(mockConfig, section, "existent-key"), "foo");
+ }
--- End diff --
The test logic is different with clojure's
test-returns-first-value-for-valid-key
> port backtype.storm.security.auth.AuthUtils-test to java
> --------------------------------------------------------
>
> Key: STORM-1233
> URL: https://issues.apache.org/jira/browse/STORM-1233
> Project: Apache Storm
> Issue Type: New Feature
> Reporter: Robert Joseph Evans
> Assignee: Alessandro Bellina
> Labels: java-migration, jstorm-merger
>
> Just a test moving to junit
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)