-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add missing fields when update classification template (#1255)
- Loading branch information
1 parent
236a036
commit f17f817
Showing
6 changed files
with
317 additions
and
12 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
src/intTest/java/com/box/sdk/BoxClassificationTemplateIT.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,95 @@ | ||
package com.box.sdk; | ||
|
||
import static com.box.sdk.BoxApiProvider.jwtApiForServiceAccount; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.Test; | ||
|
||
public class BoxClassificationTemplateIT { | ||
|
||
public MetadataTemplate getOrCreateClassificationTemplate(BoxAPIConnection api) { | ||
try { | ||
return MetadataTemplate.getMetadataTemplate(api, Metadata.CLASSIFICATION_TEMPLATE_KEY); | ||
} catch (BoxAPIException e) { | ||
assertEquals(e.getResponseCode(), 404); | ||
} | ||
|
||
MetadataTemplate.Field classification = new MetadataTemplate.Field(); | ||
classification.setType("enum"); | ||
classification.setKey("Box__Security__Classification__Key"); | ||
classification.setDisplayName("Classification"); | ||
classification.setIsHidden(false); | ||
|
||
List<String> options = new ArrayList<String>(); | ||
options.add("sensitive"); | ||
classification.setOptions(options); | ||
|
||
List<MetadataTemplate.Field> fields = new ArrayList<MetadataTemplate.Field>(); | ||
fields.add(classification); | ||
|
||
return MetadataTemplate.createMetadataTemplate(api, Metadata.ENTERPRISE_METADATA_SCOPE, | ||
Metadata.CLASSIFICATION_TEMPLATE_KEY, "Classification", false, fields); | ||
} | ||
|
||
@Test | ||
public void getUpdateClassificationTemplate() { | ||
BoxAPIConnection api = jwtApiForServiceAccount(); | ||
MetadataTemplate template = getOrCreateClassificationTemplate(api); | ||
String fieldKey = template.getFields().get(0).getKey(); | ||
String optionKey = template.getFields().get(0).getOptionsObjects().get(0).getKey(); | ||
|
||
List<MetadataTemplate.FieldOperation> updates = new ArrayList<MetadataTemplate.FieldOperation>(); | ||
String update = "{\n" | ||
+ " \"op\": \"editEnumOption\",\n" | ||
+ " \"fieldKey\": \"" + fieldKey + "\",\n" | ||
+ " \"enumOptionKey\": \"" + optionKey + "\",\n" | ||
+ " \"data\": {\n" | ||
+ " \"key\": \"" + optionKey + "\",\n" | ||
+ " \"staticConfig\": {\n" | ||
+ " \"classification\": {\n" | ||
+ " \"classificationDefinition\": \"Sensitive information.\",\n" | ||
+ " \"colorID\": 4\n" | ||
+ " }\n" | ||
+ " }\n" | ||
+ " }\n" | ||
+ "}"; | ||
updates.add(new MetadataTemplate.FieldOperation(update)); | ||
|
||
MetadataTemplate updatedTemplate = MetadataTemplate.updateMetadataTemplate(api, | ||
Metadata.ENTERPRISE_METADATA_SCOPE, Metadata.CLASSIFICATION_TEMPLATE_KEY, updates); | ||
MetadataTemplate.Option updatedOption = updatedTemplate.getFields().get(0).getOptionsObjects().get(0); | ||
assertEquals(updatedOption.getKey(), "Sensitive"); | ||
assertEquals( | ||
updatedOption.getStaticConfig().getClassification().getString("classificationDefinition", | ||
"null"), | ||
"Sensitive information."); | ||
assertEquals(updatedOption.getStaticConfig().getClassification().getInt("colorID", 0), | ||
4); | ||
update = "{\n" | ||
+ " \"op\": \"editEnumOption\",\n" | ||
+ " \"fieldKey\": \"" + fieldKey + "\",\n" | ||
+ " \"enumOptionKey\": \"" + optionKey + "\",\n" | ||
+ " \"data\": {\n" | ||
+ " \"key\": \"" + optionKey + "\",\n" | ||
+ " \"staticConfig\": {\n" | ||
+ " \"classification\": {\n" | ||
+ " \"classificationDefinition\": \"Top Sensitive information.\",\n" | ||
+ " \"colorID\": 5\n" | ||
+ " }\n" | ||
+ " }\n" | ||
+ " }\n" | ||
+ "}"; | ||
updates.clear(); | ||
updates.add(new MetadataTemplate.FieldOperation(update)); | ||
|
||
updatedTemplate = MetadataTemplate.updateMetadataTemplate(api, Metadata.ENTERPRISE_METADATA_SCOPE, | ||
Metadata.CLASSIFICATION_TEMPLATE_KEY, updates); | ||
updatedOption = updatedTemplate.getFields().get(0).getOptionsObjects().get(0); | ||
assertEquals(updatedOption.getKey(), "Sensitive"); | ||
assertEquals(updatedOption.getStaticConfig().getClassification().getString("classificationDefinition", | ||
"null"), "Top Sensitive information."); | ||
assertEquals(updatedOption.getStaticConfig().getClassification().getInt("colorID", 0), 5); | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/test/Fixtures/BoxMetadataTemplate/UpdateMetadataTemplateWithStaticConfig200.json
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,28 @@ | ||
|
||
{ | ||
"id": "f7a9891f", | ||
"templateKey": "documentFlow03", | ||
"scope": "enterprise", | ||
"displayName": "Document Flow 03", | ||
"hidden": false, | ||
"fields": [ | ||
{ | ||
"type": "enum", | ||
"key": "Box__Security__Classification__Key", | ||
"displayName": "Classification", | ||
"hidden": false, | ||
"options": [ | ||
{ | ||
"key": "Classified", | ||
"staticConfig": { | ||
"classification": { | ||
"colorID": 4, | ||
"classificationDefinition": "Top Seret" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"copyInstanceOnItemCopy": true | ||
} |
Oops, something went wrong.