|
1 | 1 | import com.contentstack.utils.Utils;
|
2 | 2 | import com.contentstack.utils.callbacks.Option;
|
3 | 3 | import com.contentstack.utils.embedded.StyleType;
|
| 4 | +import com.contentstack.utils.helper.Metadata; |
4 | 5 | import com.contentstack.utils.render.DefaultOption;
|
| 6 | +import org.json.JSONArray; |
5 | 7 | import org.json.JSONObject;
|
6 | 8 | import org.junit.BeforeClass;
|
7 | 9 | import org.junit.FixMethodOrder;
|
8 | 10 | import org.junit.Test;
|
9 | 11 | import org.junit.runners.MethodSorters;
|
10 |
| - |
11 | 12 | import java.io.IOException;
|
12 | 13 | import java.util.logging.Level;
|
13 | 14 | import java.util.logging.Logger;
|
@@ -51,136 +52,123 @@ public void test_02_WithoutKeyPath() {
|
51 | 52 | Utils.render(localJsonObj, null, new DefaultOption());
|
52 | 53 | }
|
53 | 54 |
|
54 |
| -// @Test |
55 |
| -// public void test_03_EmbeddedBlockEntry() { |
56 |
| -// JSONArray rteArray = null; |
57 |
| -// // Find the rich_text_editor available in the Object |
58 |
| -// boolean available = localJsonObj.has("rich_text_editor"); |
59 |
| -// if (available) { |
60 |
| -// Object RTE = localJsonObj.get("rich_text_editor"); |
61 |
| -// rteArray = ((JSONArray) RTE); |
62 |
| -// } |
63 |
| -// assert rteArray != null; |
64 |
| -// Utils.renderContents(rteArray, localJsonObj, (embeddedObject, metadata) -> { |
65 |
| -// StyleType type = metadata.getStyleType(); |
66 |
| -// if (type == StyleType.BLOCK) { |
67 |
| -// String title = embeddedObject.getString("title"); |
68 |
| -// String multi_line = embeddedObject.getString("multi_line"); |
69 |
| -// return "<p>" + title + "</p><span>" + multi_line + "</span>"; |
70 |
| -// } |
71 |
| -// return null; |
72 |
| -// }); |
73 |
| -// |
74 |
| -// Utils.renderContents(rteArray, localJsonObj, (embeddedObject, metadata) -> { |
75 |
| -// if (metadata.getStyleType() == StyleType.BLOCK) { |
76 |
| -// String title = embeddedObject.getString("title"); |
77 |
| -// String multi_line = embeddedObject.getString("multi_line"); |
78 |
| -// return "<p>" + title + "</p><span>" + multi_line + "</span>"; |
79 |
| -//// case StyleType.INLINE: |
80 |
| -//// String titleInline = embeddedObject.getString("title"); |
81 |
| -//// String mlInline = embeddedObject.getString("multi_line"); |
82 |
| -//// return "<p>" + titleInline + "</p><span>" + mlInline + "</span>"; |
83 |
| -//// case LINKED: |
84 |
| -//// String titleLinked = embeddedObject.getString("title"); |
85 |
| -//// String mlLinked = embeddedObject.getString("multi_line"); |
86 |
| -//// return "<p>" + titleLinked + "</p><span>" + mlLinked + "</span>"; |
87 |
| -//// case DISPLAYABLE: |
88 |
| -//// String titleDiplayable = embeddedObject.getString("title"); |
89 |
| -//// String mlDiplayable = embeddedObject.getString("multi_line"); |
90 |
| -//// return "<p>" + titleDiplayable + "</p><span>" + mlDiplayable + "</span>"; |
91 |
| -// } |
92 |
| -// return null; |
93 |
| -// }); |
94 |
| -// } |
95 |
| - |
96 |
| - |
97 |
| -// @Test |
98 |
| -// public void test_2_embedded_inline_entry() { |
99 |
| -// JSONArray rteArray = null; |
100 |
| -// boolean available = localJsonObj.has("rich_text_editor"); |
101 |
| -// if (available) { |
102 |
| -// Object RTE = localJsonObj.get("rich_text_editor"); |
103 |
| -// rteArray = ((JSONArray) RTE); |
104 |
| -// } |
105 |
| -// assert rteArray != null; |
106 |
| -// Utils.renderContents(rteArray, localJsonObj, (embeddedObject, metadata) -> { |
107 |
| -// switch (metadata.getStyleType()) { |
108 |
| -// case BLOCK: |
109 |
| -// // statements of BLOCK |
110 |
| -// String title = embeddedObject.getString("title"); |
111 |
| -// String multi_line = embeddedObject.getString("multi_line"); |
112 |
| -// return "<p>" + title + "</p><span>" + multi_line + "</span>"; |
113 |
| -// case INLINE: |
114 |
| -// // statements of INLINE |
115 |
| -// return null; |
116 |
| -// |
117 |
| -// case LINKED: |
118 |
| -// // statements of LINKED |
119 |
| -// return null; |
120 |
| -// |
121 |
| -// default: |
122 |
| -// return null; |
123 |
| -// } |
124 |
| -// }); |
125 |
| -// } |
126 |
| -// |
127 |
| -// |
128 |
| -// @Test |
129 |
| -// public void test_3_embedded_linked_entry() { |
130 |
| -// JSONArray rteArray = null; |
131 |
| -// boolean available = localJsonObj.has("rich_text_editor"); |
132 |
| -// if (available) { |
133 |
| -// Object RTE = localJsonObj.get("rich_text_editor"); |
134 |
| -// rteArray = ((JSONArray) RTE); |
135 |
| -// //System.out.println(rteArray); |
136 |
| -// } |
137 |
| -// assert rteArray != null; |
138 |
| -// Utils.renderContents(rteArray, localJsonObj, (embeddedObject, metadata) -> { |
139 |
| -// switch (metadata.getStyleType()) { |
140 |
| -// case BLOCK: |
141 |
| -// // statements of BLOCK |
142 |
| -// //blockRTE(); |
143 |
| -// String title = embeddedObject.getString("title"); |
144 |
| -// String multi_line = embeddedObject.getString("multi_line"); |
145 |
| -// return "<p>" + title + "</p><span>" + multi_line + "</span>"; |
146 |
| -// |
147 |
| -// case INLINE: |
148 |
| -// // statements of INLINE |
149 |
| -// return null; |
150 |
| -// |
151 |
| -// case LINKED: |
152 |
| -// // statements of LINKED |
153 |
| -// return null; |
154 |
| -// |
155 |
| -// default: |
156 |
| -// return null; |
157 |
| -// } |
158 |
| -// |
159 |
| -// }); |
160 |
| -// } |
161 |
| -// |
162 |
| -// |
163 |
| -// @Test |
164 |
| -// public void test_embedded_displayable_asset() { |
165 |
| -// JSONArray rteArray = null; |
166 |
| -// boolean available = localJsonObj.has("rich_text_editor"); |
167 |
| -// if (available) { |
168 |
| -// Object RTE = localJsonObj.get("rich_text_editor"); |
169 |
| -// rteArray = ((JSONArray) RTE); |
170 |
| -// } |
171 |
| -// assert rteArray != null; |
172 |
| -// Utils.renderContents(rteArray, localJsonObj, (embeddedObject, metadata) -> { |
173 |
| -// if (metadata.getStyleType() == StyleType.DISPLAY) {// statements of displayable |
174 |
| -// return null; |
175 |
| -// } |
176 |
| -// return null; |
177 |
| -// }); |
178 |
| -// } |
179 |
| -// |
180 |
| -// @Test |
181 |
| -// public void justTest(){ |
182 |
| -// //String[] blankArray = new String[0]; |
183 |
| -// //new Utils().render({}, null, eck); |
184 |
| -// } |
| 55 | + @Test |
| 56 | + public void test_03_EmbeddedBlockEntry() { |
| 57 | + JSONArray rteArray = null; |
| 58 | + boolean available = localJsonObj.has("rich_text_editor"); |
| 59 | + if (available) { |
| 60 | + Object RTE = localJsonObj.get("rich_text_editor"); |
| 61 | + rteArray = ((JSONArray) RTE); |
| 62 | + } |
| 63 | + assert rteArray != null; |
| 64 | + Utils.renderContents(rteArray, localJsonObj, (embeddedObject, metadata) -> { |
| 65 | + StyleType type = metadata.getStyleType(); |
| 66 | + if (type == StyleType.BLOCK) { |
| 67 | + String title = embeddedObject.getString("title"); |
| 68 | + String multi_line = embeddedObject.getString("multi_line"); |
| 69 | + return "<p>" + title + "</p><span>" + multi_line + "</span>"; |
| 70 | + } |
| 71 | + return null; |
| 72 | + }); |
| 73 | + |
| 74 | + Utils.renderContents(rteArray, localJsonObj, (embeddedObject, metadata) -> { |
| 75 | + if (metadata.getStyleType() == StyleType.BLOCK) { |
| 76 | + String title = embeddedObject.getString("title"); |
| 77 | + String multi_line = embeddedObject.getString("multi_line"); |
| 78 | + return "<p>" + title + "</p><span>" + multi_line + "</span>"; |
| 79 | + } |
| 80 | + return null; |
| 81 | + }); |
| 82 | + } |
| 83 | + |
| 84 | + |
| 85 | + @Test |
| 86 | + public void test_2_embedded_inline_entry() { |
| 87 | + JSONArray rteArray = null; |
| 88 | + boolean available = localJsonObj.has("rich_text_editor"); |
| 89 | + if (available) { |
| 90 | + Object RTE = localJsonObj.get("rich_text_editor"); |
| 91 | + rteArray = ((JSONArray) RTE); |
| 92 | + } |
| 93 | + assert rteArray != null; |
| 94 | + Utils.renderContents(rteArray, localJsonObj, (embeddedObject, metadata) -> { |
| 95 | + switch (metadata.getStyleType()) { |
| 96 | + case BLOCK: |
| 97 | + // statements of BLOCK |
| 98 | + String title = embeddedObject.getString("title"); |
| 99 | + String multi_line = embeddedObject.getString("multi_line"); |
| 100 | + return "<p>" + title + "</p><span>" + multi_line + "</span>"; |
| 101 | + case INLINE: |
| 102 | + // statements of INLINE |
| 103 | + return null; |
| 104 | + |
| 105 | + case LINK: |
| 106 | + // statements of LINKED |
| 107 | + return null; |
| 108 | + |
| 109 | + default: |
| 110 | + return null; |
| 111 | + } |
| 112 | + }); |
| 113 | + } |
| 114 | + |
| 115 | + |
| 116 | + @Test |
| 117 | + public void test_3_embedded_linked_entry() { |
| 118 | + JSONArray rteArray = null; |
| 119 | + boolean available = localJsonObj.has("rich_text_editor"); |
| 120 | + if (available) { |
| 121 | + Object RTE = localJsonObj.get("rich_text_editor"); |
| 122 | + rteArray = ((JSONArray) RTE); |
| 123 | + } |
| 124 | + assert rteArray != null; |
| 125 | + Utils.renderContents(rteArray, localJsonObj, (embeddedObject, metadata) -> { |
| 126 | + switch (metadata.getStyleType()) { |
| 127 | + case BLOCK: |
| 128 | + //Statements of BLOCK |
| 129 | + //blockRTE(); |
| 130 | + String title = embeddedObject.getString("title"); |
| 131 | + String multi_line = embeddedObject.getString("multi_line"); |
| 132 | + return "<p>" + title + "</p><span>" + multi_line + "</span>"; |
| 133 | + |
| 134 | + case INLINE: |
| 135 | + // Statements of INLINE |
| 136 | + return null; |
| 137 | + |
| 138 | + case LINK: |
| 139 | + // Statements of LINKED |
| 140 | + return null; |
| 141 | + |
| 142 | + default: |
| 143 | + return null; |
| 144 | + } |
| 145 | + |
| 146 | + }); |
| 147 | + } |
| 148 | + |
| 149 | + |
| 150 | + @Test |
| 151 | + public void test_embedded_displayable_asset() { |
| 152 | + JSONObject rteObject = null; |
| 153 | + boolean available = localJsonObj.has("rich_text_editor"); |
| 154 | + if (available) { |
| 155 | + Object RTE = localJsonObj.get("rich_text_editor"); |
| 156 | + rteObject = ((JSONObject) RTE); |
| 157 | + } |
| 158 | + assert rteObject != null; |
| 159 | + String[] keyPath = { |
| 160 | + "rich_text_editor", "global_rich_multiple.group.rich_text_editor" |
| 161 | + }; |
| 162 | + Utils.render(rteObject, keyPath, new Option() { |
| 163 | + @Override |
| 164 | + public String renderOptions(JSONObject embeddedObject, Metadata metadata) { |
| 165 | + if (metadata.getStyleType()==StyleType.BLOCK){ |
| 166 | + // Do something |
| 167 | + } |
| 168 | + return null; |
| 169 | + } |
| 170 | + }); |
| 171 | + } |
| 172 | + |
185 | 173 |
|
186 | 174 | }
|
0 commit comments