-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
151 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
!!javax.script.ScriptEngineManager [ | ||
!!java.net.URLClassLoader [[ | ||
!!java.net.URL ["http://localhost"] | ||
]] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...portal/src/test/java/com/ctrip/framework/apollo/portal/controller/ItemControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.ctrip.framework.apollo.portal.controller; | ||
|
||
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; | ||
import com.ctrip.framework.apollo.portal.component.PermissionValidator; | ||
import com.ctrip.framework.apollo.portal.entity.model.NamespaceTextModel; | ||
import com.ctrip.framework.apollo.portal.service.ItemService; | ||
import com.ctrip.framework.apollo.portal.service.NamespaceService; | ||
import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; | ||
import com.google.common.base.Charsets; | ||
import com.google.common.io.Files; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.yaml.snakeyaml.constructor.ConstructorException; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ItemControllerTest { | ||
|
||
@Mock | ||
private ItemService configService; | ||
@Mock | ||
private NamespaceService namespaceService; | ||
@Mock | ||
private UserInfoHolder userInfoHolder; | ||
@Mock | ||
private PermissionValidator permissionValidator; | ||
|
||
@InjectMocks | ||
private ItemController itemController; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
itemController = new ItemController(configService, userInfoHolder, permissionValidator, | ||
namespaceService); | ||
} | ||
|
||
@Test | ||
public void yamlSyntaxCheckOK() throws Exception { | ||
String yaml = loadYaml("case1.yaml"); | ||
|
||
itemController.doSyntaxCheck(assemble(ConfigFileFormat.YAML.getValue(), yaml)); | ||
} | ||
|
||
@Test(expected = IllegalStateException.class) | ||
public void yamlSyntaxCheckWithDuplicatedValue() throws Exception { | ||
String yaml = loadYaml("case2.yaml"); | ||
|
||
itemController.doSyntaxCheck(assemble(ConfigFileFormat.YAML.getValue(), yaml)); | ||
} | ||
|
||
@Test(expected = ConstructorException.class) | ||
public void yamlSyntaxCheckWithUnsupportedType() throws Exception { | ||
String yaml = loadYaml("case3.yaml"); | ||
|
||
itemController.doSyntaxCheck(assemble(ConfigFileFormat.YAML.getValue(), yaml)); | ||
} | ||
|
||
private NamespaceTextModel assemble(String format, String content) { | ||
NamespaceTextModel model = new NamespaceTextModel(); | ||
model.setFormat(format); | ||
model.setConfigText(content); | ||
|
||
return model; | ||
} | ||
|
||
private String loadYaml(String caseName) throws IOException { | ||
File file = new File("src/test/resources/yaml/" + caseName); | ||
|
||
return Files.toString(file, Charsets.UTF_8); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
root: | ||
key1: "someValue" | ||
key2: 100 | ||
key3: | ||
key4: | ||
key5: '(%sender%) %message%' | ||
key6: '* %sender% %message%' | ||
# commented: "xxx" | ||
list: | ||
- 'item 1' | ||
- 'item 2' | ||
intList: | ||
- 100 | ||
- 200 | ||
listOfMap: | ||
- key: '#mychannel' | ||
value: '' | ||
- key: '#myprivatechannel' | ||
value: 'mypassword' | ||
listOfList: | ||
- - 'a1' | ||
- 'a2' | ||
- - 'b1' | ||
- 'b2' | ||
listOfList2: [ ['a1', 'a2'], ['b1', 'b2'] ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
root: | ||
key1: "someValue" | ||
key2: 100 | ||
key1: "anotherValue" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
!!javax.script.ScriptEngineManager [ | ||
!!java.net.URLClassLoader [[ | ||
!!java.net.URL ["http://localhost"] | ||
]] | ||
] |