Skip to content

Commit

Permalink
Resolves #116; Fixes CSV Asset Importer ability to save "true" or "fa…
Browse files Browse the repository at this point in the history
…lse" String values
  • Loading branch information
davidjgonzalez committed Dec 14, 2015
1 parent 1947c32 commit 5451a7e
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 3 deletions.
6 changes: 6 additions & 0 deletions bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@
<version>2.1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public T[] getMultiData(String data) {
return list.toArray((T[]) Array.newInstance((this.getDataType()), 0));
}

private <T> T toObjectType(String data, Class<T> klass) {
protected <T> T toObjectType(String data, Class<T> klass) {
data = StringUtils.trim(data);

if (Double.class.equals(klass)) {
Expand All @@ -130,9 +130,11 @@ private <T> T toObjectType(String data, Class<T> klass) {
} catch (NumberFormatException ex) {
return null;
}
} else if (StringUtils.equalsIgnoreCase("true", data)) {
} else if (StringUtils.equalsIgnoreCase("true", data)
&& Boolean.class.equals(klass)) {
return klass.cast(Boolean.TRUE);
} else if (StringUtils.equalsIgnoreCase("false", data)) {
} else if (StringUtils.equalsIgnoreCase("false", data)
&& Boolean.class.equals(klass)) {
return klass.cast(Boolean.FALSE);
} else if ((Date.class.equals(Date.class)
|| Calendar.class.equals(Calendar.class))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* #%L
* ACS AEM Tools Bundle
* %%
* Copyright (C) 2015 Adobe
* %%
* Licensed 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.
* #L%
*/

package com.adobe.acs.tools.csv_asset_importer.impl;


import org.junit.Assert;
import org.junit.Test;

public class ColumnTest {

@Test
public void testGetData() throws Exception {
Column col;

// Default (String)
col = new Column("title", 0);
Assert.assertEquals("test", col.getData("test"));

// String
col = new Column("title {{ String }}", 0);
Assert.assertEquals("test", col.getData("test"));

// String (true value)
col = new Column("title {{ String }}", 0);
Assert.assertEquals("true", col.getData("true"));

// Long
col = new Column("title {{ Long }}", 0);
Assert.assertEquals(100L, col.getData("100"));

// Int
col = new Column("title {{ Int }}", 0);
Assert.assertEquals(100L, col.getData("100"));

// Integer
col = new Column("title {{ Integer }}", 0);
Assert.assertEquals(100L, col.getData("100"));

// Double
col = new Column("title {{ Double }}", 0);
Assert.assertEquals(100.001D, col.getData("100.001"));

// Boolean
col = new Column("title {{ Boolean }}", 0);
Assert.assertEquals(true, col.getData("true"));

col = new Column("title {{ Boolean }}", 0);
Assert.assertEquals(false, col.getData("FALSE"));
}

@Test
public void testToObjectType() throws Exception {
Column col;

// Default (String)
col = new Column("title", 0);
Assert.assertEquals("test", col.toObjectType("test", String.class));

// String (true value)
col = new Column("title {{ String }}", 0);
Assert.assertEquals("true", col.toObjectType("true", String.class));
}

@Test
public void testGetPropertyName() throws Exception {
Column col;

col = new Column("title", 0);
Assert.assertEquals("title", col.getPropertyName());

col = new Column("title {{ String }}", 0);
Assert.assertEquals("title", col.getPropertyName());

col = new Column("title {{ String : multi }}", 0);
Assert.assertEquals("title", col.getPropertyName());

col = new Column("title {{String}}", 0);
Assert.assertEquals("title", col.getPropertyName());

col = new Column("title {{String:multi}}", 0);
Assert.assertEquals("title", col.getPropertyName());
}
}

0 comments on commit 5451a7e

Please sign in to comment.