Skip to content

Commit 5451a7e

Browse files
Resolves #116; Fixes CSV Asset Importer ability to save "true" or "false" String values
1 parent 1947c32 commit 5451a7e

File tree

3 files changed

+112
-3
lines changed

3 files changed

+112
-3
lines changed

bundle/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@
258258
<version>2.1.4</version>
259259
<scope>provided</scope>
260260
</dependency>
261+
<dependency>
262+
<groupId>junit</groupId>
263+
<artifactId>junit</artifactId>
264+
<version>4.12</version>
265+
<scope>test</scope>
266+
</dependency>
261267
</dependencies>
262268

263269
<profiles>

bundle/src/main/java/com/adobe/acs/tools/csv_asset_importer/impl/Column.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public T[] getMultiData(String data) {
109109
return list.toArray((T[]) Array.newInstance((this.getDataType()), 0));
110110
}
111111

112-
private <T> T toObjectType(String data, Class<T> klass) {
112+
protected <T> T toObjectType(String data, Class<T> klass) {
113113
data = StringUtils.trim(data);
114114

115115
if (Double.class.equals(klass)) {
@@ -130,9 +130,11 @@ private <T> T toObjectType(String data, Class<T> klass) {
130130
} catch (NumberFormatException ex) {
131131
return null;
132132
}
133-
} else if (StringUtils.equalsIgnoreCase("true", data)) {
133+
} else if (StringUtils.equalsIgnoreCase("true", data)
134+
&& Boolean.class.equals(klass)) {
134135
return klass.cast(Boolean.TRUE);
135-
} else if (StringUtils.equalsIgnoreCase("false", data)) {
136+
} else if (StringUtils.equalsIgnoreCase("false", data)
137+
&& Boolean.class.equals(klass)) {
136138
return klass.cast(Boolean.FALSE);
137139
} else if ((Date.class.equals(Date.class)
138140
|| Calendar.class.equals(Calendar.class))
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* #%L
3+
* ACS AEM Tools Bundle
4+
* %%
5+
* Copyright (C) 2015 Adobe
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
21+
package com.adobe.acs.tools.csv_asset_importer.impl;
22+
23+
24+
import org.junit.Assert;
25+
import org.junit.Test;
26+
27+
public class ColumnTest {
28+
29+
@Test
30+
public void testGetData() throws Exception {
31+
Column col;
32+
33+
// Default (String)
34+
col = new Column("title", 0);
35+
Assert.assertEquals("test", col.getData("test"));
36+
37+
// String
38+
col = new Column("title {{ String }}", 0);
39+
Assert.assertEquals("test", col.getData("test"));
40+
41+
// String (true value)
42+
col = new Column("title {{ String }}", 0);
43+
Assert.assertEquals("true", col.getData("true"));
44+
45+
// Long
46+
col = new Column("title {{ Long }}", 0);
47+
Assert.assertEquals(100L, col.getData("100"));
48+
49+
// Int
50+
col = new Column("title {{ Int }}", 0);
51+
Assert.assertEquals(100L, col.getData("100"));
52+
53+
// Integer
54+
col = new Column("title {{ Integer }}", 0);
55+
Assert.assertEquals(100L, col.getData("100"));
56+
57+
// Double
58+
col = new Column("title {{ Double }}", 0);
59+
Assert.assertEquals(100.001D, col.getData("100.001"));
60+
61+
// Boolean
62+
col = new Column("title {{ Boolean }}", 0);
63+
Assert.assertEquals(true, col.getData("true"));
64+
65+
col = new Column("title {{ Boolean }}", 0);
66+
Assert.assertEquals(false, col.getData("FALSE"));
67+
}
68+
69+
@Test
70+
public void testToObjectType() throws Exception {
71+
Column col;
72+
73+
// Default (String)
74+
col = new Column("title", 0);
75+
Assert.assertEquals("test", col.toObjectType("test", String.class));
76+
77+
// String (true value)
78+
col = new Column("title {{ String }}", 0);
79+
Assert.assertEquals("true", col.toObjectType("true", String.class));
80+
}
81+
82+
@Test
83+
public void testGetPropertyName() throws Exception {
84+
Column col;
85+
86+
col = new Column("title", 0);
87+
Assert.assertEquals("title", col.getPropertyName());
88+
89+
col = new Column("title {{ String }}", 0);
90+
Assert.assertEquals("title", col.getPropertyName());
91+
92+
col = new Column("title {{ String : multi }}", 0);
93+
Assert.assertEquals("title", col.getPropertyName());
94+
95+
col = new Column("title {{String}}", 0);
96+
Assert.assertEquals("title", col.getPropertyName());
97+
98+
col = new Column("title {{String:multi}}", 0);
99+
Assert.assertEquals("title", col.getPropertyName());
100+
}
101+
}

0 commit comments

Comments
 (0)