You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by gu...@apache.org on 2019/03/25 01:30:03 UTC
[lucene-solr] branch branch_8x updated: sysout checking SOLR-13322
This is an automated email from the ASF dual-hosted git repository.
gus pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/branch_8x by this push:
new cbaa68e sysout checking SOLR-13322
cbaa68e is described below
commit cbaa68e9c0bad859d70ae4a8885bbecde6b79453
Author: Gus Heck <gu...@apache.org>
AuthorDate: Sun Mar 24 21:29:16 2019 -0400
sysout checking SOLR-13322
---
.../apache/solr/internal/csv/writer/CSVConfig.java | 285 ---------------------
.../solr/internal/csv/writer/CSVConfigGuesser.java | 187 --------------
.../apache/solr/internal/csv/writer/CSVField.java | 109 --------
.../apache/solr/internal/csv/writer/CSVWriter.java | 134 ----------
.../solr/internal/csv/writer/package-info.java | 25 --
.../internal/csv/writer/CSVConfigGuesserTest.java | 87 -------
.../solr/internal/csv/writer/CSVConfigTest.java | 98 -------
.../solr/internal/csv/writer/CSVFieldTest.java | 46 ----
.../solr/internal/csv/writer/CSVWriterTest.java | 54 ----
9 files changed, 1025 deletions(-)
diff --git a/solr/core/src/java/org/apache/solr/internal/csv/writer/CSVConfig.java b/solr/core/src/java/org/apache/solr/internal/csv/writer/CSVConfig.java
deleted file mode 100644
index c295abe..0000000
--- a/solr/core/src/java/org/apache/solr/internal/csv/writer/CSVConfig.java
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-package org.apache.solr.internal.csv.writer;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * The CSVConfig is used to configure the CSV writer
- *
- * @deprecated Classes in this package are not used in any code other than it's own tests and will be removed in 9.0
- */
-@Deprecated
-public class CSVConfig {
-
- /** specifies if it is a fixed width csv file **/
- private boolean fixedWidth;
- /** list of fields **/
- private List fields;
-
- /** Do no do any filling **/
- public static final int FILLNONE = 0;
- /** Fill content the the left. Mainly usable together with fixedWidth **/
- public static final int FILLLEFT = 1;
- /** Fill content to the right. Mainly usable together with fixedWidth **/
- public static final int FILLRIGHT = 2;
-
- /** The fill pattern */
- private int fill;
- /** The fill char. Defaults to a space */
- private char fillChar = ' ';
- /** The separator character. Defaults to , */
- private char delimiter = ',';
- /** Should we ignore the delimiter. Defaults to false */
- private boolean ignoreDelimiter = false;
- /** the value delimiter. Defaults to " */
- private char valueDelimiter = '"';
- /** Should we ignore the value delimiter. Defaults to true */
- private boolean ignoreValueDelimiter = true;
- /** Specifies if we want to use a field header */
- private boolean fieldHeader = false;
- /** Specifies if the end of the line needs to be trimmed */
- private boolean endTrimmed = false;
- /**
- *
- */
- public CSVConfig() {
- super();
- }
-
- /**
- * @return if the CSV file is fixedWidth
- */
- public boolean isFixedWidth() {
- return fixedWidth;
- }
-
- /**
- * Specify if the CSV file is fixed width.
- * Defaults to false
- * @param fixedWidth the fixedwidth
- */
- public void setFixedWidth(boolean fixedWidth) {
- this.fixedWidth = fixedWidth;
- }
-
- public void addField(CSVField field) {
- if (fields == null) {
- fields = new ArrayList();
- }
- fields.add(field);
- }
-
- /**
- * Set the fields that should be used by the writer.
- * This will overwrite currently added fields completely!
- * @param csvFields the csvfields array. If null it will do nothing
- */
- public void setFields(CSVField[] csvFields) {
- if (csvFields == null) {
- return;
- }
- fields = new ArrayList(Arrays.asList(csvFields));
- }
-
- /**
- * Set the fields that should be used by the writer
- * @param csvField a collection with fields. If null it will do nothing
- */
- public void setFields(Collection csvField) {
- if (csvField == null) {
- return;
- }
- fields = new ArrayList(csvField);
- }
-
- /**
- * @return an array with the known fields (even if no fields are specified)
- */
- public CSVField[] getFields() {
- CSVField[] csvFields = new CSVField[0];
- if (fields != null) {
- return (CSVField[]) fields.toArray(csvFields);
- }
- return csvFields;
- }
-
- public CSVField getField(String name) {
- if (fields == null || name == null) {
- return null;
- }
- for(int i = 0; i < fields.size(); i++) {
- CSVField field = (CSVField) fields.get(i);
- if (name.equals(field.getName())) {
- return field;
- }
- }
- return null;
- }
-
- /**
- * @return the fill pattern.
- */
- public int getFill() {
- return fill;
- }
-
- /**
- * Set the fill pattern. Defaults to {@link #FILLNONE}
- * <br>Other options are : {@link #FILLLEFT} and {@link #FILLRIGHT}
- * @param fill the fill pattern.
- */
- public void setFill(int fill) {
- this.fill = fill;
- }
-
- /**
- *
- * @return the fillchar. Defaults to a space.
- */
- public char getFillChar() {
- return fillChar;
- }
-
- /**
- * Set the fill char
- * @param fillChar the fill char
- */
- public void setFillChar(char fillChar) {
- this.fillChar = fillChar;
- }
-
- /**
- * @return the delimeter used.
- */
- public char getDelimiter() {
- return delimiter;
- }
-
- /**
- * Set the delimiter to use
- * @param delimiter the delimiter character.
- */
- public void setDelimiter(char delimiter) {
- this.delimiter = delimiter;
- }
-
- /**
- * @return if the writer should ignore the delimiter character.
- */
- public boolean isDelimiterIgnored() {
- return ignoreDelimiter;
- }
-
- /**
- * Specify if the writer should ignore the delimiter.
- * @param ignoreDelimiter defaults to false.
- */
- public void setIgnoreDelimiter(boolean ignoreDelimiter) {
- this.ignoreDelimiter = ignoreDelimiter;
- }
-
- /**
- * @return the value delimeter used. Defaults to "
- */
- public char getValueDelimiter() {
- return valueDelimiter;
- }
-
- /**
- * Set the value delimiter to use
- * @param valueDelimiter the value delimiter character.
- */
- public void setValueDelimiter(char valueDelimiter) {
- this.valueDelimiter = valueDelimiter;
- }
-
- /**
- * @return if the writer should ignore the value delimiter character.
- * Defaults to true.
- */
- public boolean isValueDelimiterIgnored() {
- return ignoreValueDelimiter;
- }
-
- /**
- * Specify if the writer should ignore the value delimiter.
- * @param ignoreValueDelimiter defaults to false.
- */
- public void setIgnoreValueDelimiter(boolean ignoreValueDelimiter) {
- this.ignoreValueDelimiter = ignoreValueDelimiter;
- }
-
- /**
- * @return if a field header is used. Defaults to false
- */
- public boolean isFieldHeader() {
- return fieldHeader;
- }
- /**
- * Specify if you want to use a field header.
- * @param fieldHeader true or false.
- */
- public void setFieldHeader(boolean fieldHeader) {
- this.fieldHeader = fieldHeader;
- }
-
- /**
- * TODO..
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (obj == null && !(obj instanceof CSVConfig)) {
- return false;
- }
- return super.equals(obj);
-// CSVConfig config = (CSVConfig) obj;
-// getFill() == config.getFill()
-// getFields().equals(config.getFields())
- }
-
- /**
- * Creates a config based on a stream. It tries to guess<br>
- * NOTE : The stream will be closed.
- * @param inputStream the inputstream.
- * @return the guessed config.
- */
- public static CSVConfig guessConfig(InputStream inputStream) {
- return null;
- }
-
- /**
- * @return if the end of the line should be trimmed. Default is false.
- */
- public boolean isEndTrimmed() {
- return endTrimmed;
- }
-
- /**
- * Specify if the end of the line needs to be trimmed. Defaults to false.
- */
- public void setEndTrimmed(boolean endTrimmed) {
- this.endTrimmed = endTrimmed;
- }
-
-
-}
diff --git a/solr/core/src/java/org/apache/solr/internal/csv/writer/CSVConfigGuesser.java b/solr/core/src/java/org/apache/solr/internal/csv/writer/CSVConfigGuesser.java
deleted file mode 100644
index 586fad6..0000000
--- a/solr/core/src/java/org/apache/solr/internal/csv/writer/CSVConfigGuesser.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-package org.apache.solr.internal.csv.writer;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-
-/**
- * Tries to guess a config based on an InputStream.
- *
- * @deprecated Classes in this package are not used in any code other than it's own tests and will be removed in 9.0
- */
-@Deprecated
-public class CSVConfigGuesser {
-
- /** The stream to read */
- private InputStream in;
- /**
- * if the file has a field header (need this info, to be able to guess better)
- * Defaults to false
- */
- private boolean hasFieldHeader = false;
- /** The found config */
- protected CSVConfig config;
-
- /**
- *
- */
- public CSVConfigGuesser() {
- this.config = new CSVConfig();
- }
-
- /**
- * @param in the inputstream to guess from
- */
- public CSVConfigGuesser(InputStream in) {
- this();
- setInputStream(in);
- }
-
- public void setInputStream(InputStream in) {
- this.in = in;
- }
-
- /**
- * Allow override.
- * @return the inputstream that was set.
- */
- protected InputStream getInputStream() {
- return in;
- }
-
- /**
- * Guess the config based on the first 10 (or less when less available)
- * records of a CSV file.
- *
- * @return the guessed config.
- */
- public CSVConfig guess() {
- try {
- // tralalal
- BufferedReader bIn = new BufferedReader(new InputStreamReader(getInputStream(), StandardCharsets.UTF_8));
- String[] lines = new String[10];
- String line = null;
- int counter = 0;
- while ( (line = bIn.readLine()) != null && counter <= 10) {
- lines[counter] = line;
- counter++;
- }
- if (counter < 10) {
- // remove nulls from the array, so we can skip the null checking.
- String[] newLines = new String[counter];
- System.arraycopy(lines, 0, newLines, 0, counter);
- lines = newLines;
- }
- analyseLines(lines);
- } catch(Exception e) {
- e.printStackTrace();
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch(Exception e) {
- // ignore exception.
- }
- }
- }
- CSVConfig conf = config;
- // cleanup the config.
- config = null;
- return conf;
- }
-
- protected void analyseLines(String[] lines) {
- guessFixedWidth(lines);
- guessFieldSeparator(lines);
- }
-
- /**
- * Guess if this file is fixedwidth.
- * Just basing the fact on all lines being of the same length
- */
- protected void guessFixedWidth(String[] lines) {
- int lastLength = 0;
- // assume fixedlength.
- config.setFixedWidth(true);
- for (int i = 0; i < lines.length; i++) {
- if (i == 0) {
- lastLength = lines[i].length();
- } else {
- if (lastLength != lines[i].length()) {
- config.setFixedWidth(false);
- }
- }
- }
- }
-
-
- protected void guessFieldSeparator(String[] lines) {
- if (config.isFixedWidth()) {
- guessFixedWidthSeparator(lines);
- return;
- }
- for (int i = 0; i < lines.length; i++) {
- }
- }
-
- protected void guessFixedWidthSeparator(String[] lines) {
- // keep track of the fieldlength
- int previousMatch = -1;
- for (int i = 0; i < lines[0].length(); i++) {
- char last = ' ';
- boolean charMatches = true;
- for (int j = 0; j < lines.length; j++) {
- if (j == 0) {
- last = lines[j].charAt(i);
- }
- if (last != lines[j].charAt(i)) {
- charMatches = false;
- break;
- }
- }
- if (charMatches) {
- if (previousMatch == -1) {
- previousMatch = 0;
- }
- CSVField field = new CSVField();
- field.setName("field"+config.getFields().length+1);
- field.setSize((i-previousMatch));
- config.addField(field);
- }
- }
- }
- /**
- *
- * @return if the field uses a field header. Defaults to false.
- */
- public boolean hasFieldHeader() {
- return hasFieldHeader;
- }
-
- /**
- * Specify if the CSV file has a field header
- * @param hasFieldHeader true or false
- */
- public void setHasFieldHeader(boolean hasFieldHeader) {
- this.hasFieldHeader = hasFieldHeader;
- }
-
-
-}
diff --git a/solr/core/src/java/org/apache/solr/internal/csv/writer/CSVField.java b/solr/core/src/java/org/apache/solr/internal/csv/writer/CSVField.java
deleted file mode 100644
index ab62f55..0000000
--- a/solr/core/src/java/org/apache/solr/internal/csv/writer/CSVField.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-package org.apache.solr.internal.csv.writer;
-
-
-/**
- * @deprecated Classes in this package are not used in any code other than it's own tests and will be removed in 9.0
- */
-@Deprecated
-public class CSVField {
-
- private String name;
- private int size;
- private int fill;
- private boolean overrideFill;
-
- /**
- *
- */
- public CSVField() {
- }
-
- /**
- * @param name the name of the field
- */
- public CSVField(String name) {
- setName(name);
- }
-
- /**
- * @param name the name of the field
- * @param size the size of the field
- */
- public CSVField(String name, int size) {
- setName(name);
- setSize(size);
- }
-
- /**
- * @return the name of the field
- */
- public String getName() {
- return name;
- }
-
- /**
- * Set the name of the field
- * @param name the name
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- *
- * @return the size of the field
- */
- public int getSize() {
- return size;
- }
-
- /**
- * Set the size of the field.
- * The size will be ignored when fixedwidth is set to false in the CSVConfig
- * @param size the size of the field.
- */
- public void setSize(int size) {
- this.size = size;
- }
-
- /**
- * @return the fill pattern.
- */
- public int getFill() {
- return fill;
- }
-
- /**
- * Sets overrideFill to true.
- * @param fill the file pattern
- */
- public void setFill(int fill) {
- overrideFill = true;
- this.fill = fill;
- }
-
- /**
- * Does this field override fill ?
- *
- */
- public boolean overrideFill() {
- return overrideFill;
- }
-
-}
diff --git a/solr/core/src/java/org/apache/solr/internal/csv/writer/CSVWriter.java b/solr/core/src/java/org/apache/solr/internal/csv/writer/CSVWriter.java
deleted file mode 100644
index 6e0a561..0000000
--- a/solr/core/src/java/org/apache/solr/internal/csv/writer/CSVWriter.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-package org.apache.solr.internal.csv.writer;
-
-import java.io.Writer;
-import java.util.Arrays;
-import java.util.Map;
-
-
-/**
- * CSVWriter
- *
- * @deprecated Classes in this package are not used in any code other than it's own tests and will be removed in 9.0
- */
-@Deprecated
-public class CSVWriter {
-
- /** The CSV config **/
- private CSVConfig config;
- /** The writer **/
- private Writer writer;
- /**
- *
- */
- public CSVWriter() {
- }
-
- public CSVWriter(CSVConfig config) {
- setConfig(config);
- }
-
- public void writeRecord(Map map) {
- CSVField[] fields = config.getFields();
- try {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < fields.length; i++) {
- Object o = map.get(fields[i].getName());
- if (o != null) {
- String value = o.toString();
- value = writeValue(fields[i], value);
- sb.append(value);
- }
- if (!config.isDelimiterIgnored() && fields.length != (i+1)) {
- sb.append(config.getDelimiter());
- }
- }
- if (config.isEndTrimmed()) {
- for (int i = sb.length()-1; i >= 0; i--) {
- System.out.println("i : " + i);
- if (Character.isWhitespace(sb.charAt(i))) {
- sb.deleteCharAt(i);
- } else {
- break;
- }
- }
- }
- sb.append("\n");
- String line = sb.toString();
- writer.write(line);
- } catch(Exception e) {
- e.printStackTrace();
- }
- }
-
- protected String writeValue(CSVField field, String value) throws Exception {
- if (config.isFixedWidth()) {
- if (value.length() < field.getSize()) {
- int fillPattern = config.getFill();
- if (field.overrideFill()) {
- fillPattern = field.getFill();
- }
- StringBuilder sb = new StringBuilder();
- int fillSize = (field.getSize() - value.length());
- char[] fill = new char[fillSize];
- Arrays.fill(fill, config.getFillChar());
- if (fillPattern == CSVConfig.FILLLEFT) {
- sb.append(fill);
- sb.append(value);
- value = sb.toString();
- } else {
- // defaults to fillpattern FILLRIGHT when fixedwidth is used
- sb.append(value);
- sb.append(fill);
- value = sb.toString();
- }
- } else if (value.length() > field.getSize()) {
- // value to big..
- value = value.substring(0, field.getSize());
- }
- if (!config.isValueDelimiterIgnored()) {
- // add the value delimiter..
- value = config.getValueDelimiter()+value+config.getValueDelimiter();
- }
- }
- return value;
- }
- /**
- * @return the CVSConfig or null if not present
- */
- public CSVConfig getConfig() {
- return config;
- }
-
- /**
- * Set the CSVConfig
- * @param config the CVSConfig
- */
- public void setConfig(CSVConfig config) {
- this.config = config;
- }
-
- /**
- * Set the writer to write the CSV file to.
- * @param writer the writer.
- */
- public void setWriter(Writer writer) {
- this.writer = writer;
- }
-
-}
diff --git a/solr/core/src/java/org/apache/solr/internal/csv/writer/package-info.java b/solr/core/src/java/org/apache/solr/internal/csv/writer/package-info.java
deleted file mode 100644
index 8c19882..0000000
--- a/solr/core/src/java/org/apache/solr/internal/csv/writer/package-info.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-
-/**
- * Internal classes used for reading/writing CSV
- *
- * @deprecated Classes in this package are not used in any code other than it's own tests and will be removed in 9.0
- */
-package org.apache.solr.internal.csv.writer;
-
-
diff --git a/solr/core/src/test/org/apache/solr/internal/csv/writer/CSVConfigGuesserTest.java b/solr/core/src/test/org/apache/solr/internal/csv/writer/CSVConfigGuesserTest.java
deleted file mode 100644
index 7ece076..0000000
--- a/solr/core/src/test/org/apache/solr/internal/csv/writer/CSVConfigGuesserTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-package org.apache.solr.internal.csv.writer;
-
-import java.io.ByteArrayInputStream;
-import java.nio.charset.StandardCharsets;
-
-import junit.framework.TestCase;
-
-/**
- * Tests for the config guesser.
- */
-public class CSVConfigGuesserTest extends TestCase {
-
- public void testSetters() throws Exception {
- CSVConfigGuesser guesser = new CSVConfigGuesser();
- ByteArrayInputStream in = new ByteArrayInputStream(new byte[0]);
- guesser.setInputStream(in);
- assertEquals(in, guesser.getInputStream());
- guesser = new CSVConfigGuesser(in);
- assertEquals(in, guesser.getInputStream());
- assertEquals(false, guesser.hasFieldHeader());
- guesser.setHasFieldHeader(true);
- assertEquals(true, guesser.hasFieldHeader());
- }
- /**
- * Test a format like
- * 1234 ; abcd ; 1234 ;
- *
- */
- public void testConfigGuess1() throws Exception {
- CSVConfig expected = new CSVConfig();
- expected.setDelimiter(';');
- expected.setValueDelimiter(' ');
- expected.setFill(CSVConfig.FILLRIGHT);
- expected.setIgnoreValueDelimiter(false);
- expected.setFixedWidth(true);
- CSVField field = new CSVField();
- field.setSize(4);
- expected.addField(field);
- expected.addField(field);
- StringBuilder sb = new StringBuilder();
- sb.append("1234;abcd;1234\n");
- sb.append("abcd;1234;abcd");
- ByteArrayInputStream in = new ByteArrayInputStream(sb.toString().getBytes(StandardCharsets.UTF_8));
- CSVConfigGuesser guesser = new CSVConfigGuesser(in);
- CSVConfig guessed = guesser.guess();
- assertEquals(expected.isFixedWidth(), guessed.isFixedWidth());
- assertEquals(expected.getFields().length, guessed.getFields().length);
- assertEquals(expected.getFields()[0].getSize(), guessed.getFields()[0].getSize());
- }
- /**
- * Test a format like
- * 1234,123123,12312312,213123
- * 1,2,3,4
- *
- */
- public void testConfigGuess2() throws Exception {
- CSVConfig expected = new CSVConfig();
- expected.setDelimiter(';');
- expected.setValueDelimiter(' ');
- expected.setFill(CSVConfig.FILLRIGHT);
- expected.setIgnoreValueDelimiter(false);
-// expected.setFixedWidth(false);
- StringBuilder sb = new StringBuilder();
- sb.append("1,2,3,4\n");
- sb.append("abcd,1234,abcd,1234");
- ByteArrayInputStream in = new ByteArrayInputStream(sb.toString().getBytes(StandardCharsets.UTF_8));
- CSVConfigGuesser guesser = new CSVConfigGuesser(in);
- CSVConfig guessed = guesser.guess();
- assertEquals(expected.isFixedWidth(), guessed.isFixedWidth());
- }
-}
diff --git a/solr/core/src/test/org/apache/solr/internal/csv/writer/CSVConfigTest.java b/solr/core/src/test/org/apache/solr/internal/csv/writer/CSVConfigTest.java
deleted file mode 100644
index 67f376a..0000000
--- a/solr/core/src/test/org/apache/solr/internal/csv/writer/CSVConfigTest.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-package org.apache.solr.internal.csv.writer;
-
-import java.util.Collection;
-
-import junit.framework.TestCase;
-
-/**
- * Testcase for the CSVConfig
- */
-public class CSVConfigTest extends TestCase {
-
-
- public void testFixedWith() {
- CSVConfig config = new CSVConfig();
- assertEquals(false, config.isFixedWidth());
- config.setFixedWidth(true);
- assertEquals(true, config.isFixedWidth());
- }
-
- public void testFields() {
- CSVConfig config = new CSVConfig();
- assertEquals(0, config.getFields().length);
- config.setFields((CSVField[])null);
- assertEquals(0, config.getFields().length);
- config.setFields((Collection)null);
- assertEquals(0, config.getFields().length);
- CSVField field = new CSVField();
- field.setName("field1");
- config.addField(field);
- assertEquals(field, config.getFields()[0]);
- assertEquals(null, config.getField(null));
- assertEquals(null, config.getField("field11"));
- assertEquals(field, config.getField("field1"));
- }
-
- public void testFill() {
- CSVConfig config = new CSVConfig();
- assertEquals(CSVConfig.FILLNONE, config.getFill());
- config.setFill(CSVConfig.FILLLEFT);
- assertEquals(CSVConfig.FILLLEFT, config.getFill());
- config.setFill(CSVConfig.FILLRIGHT);
- assertEquals(CSVConfig.FILLRIGHT, config.getFill());
- assertEquals(' ', config.getFillChar());
- config.setFillChar('m');
- assertEquals('m', config.getFillChar());
- }
-
- public void testDelimiter() {
- CSVConfig config = new CSVConfig();
- assertEquals(',', config.getDelimiter());
- config.setDelimiter(';');
- assertEquals(';', config.getDelimiter());
- assertEquals(false, config.isDelimiterIgnored());
- config.setIgnoreDelimiter(true);
- assertEquals(true, config.isDelimiterIgnored());
- }
-
- public void testValueDelimiter() {
- CSVConfig config = new CSVConfig();
- assertEquals('"', config.getValueDelimiter());
- config.setValueDelimiter('m');
- assertEquals('m', config.getValueDelimiter());
- assertEquals(true, config.isValueDelimiterIgnored());
- config.setIgnoreValueDelimiter(false);
- assertEquals(false, config.isValueDelimiterIgnored());
- }
-
- public void testFieldHeader() {
- CSVConfig config = new CSVConfig();
- assertEquals(false, config.isFieldHeader());
- config.setFieldHeader(true);
- assertEquals(true, config.isFieldHeader());
- }
-
- public void testTrimEnd() {
- CSVConfig config = new CSVConfig();
- assertEquals(false, config.isEndTrimmed());
- config.setEndTrimmed(true);
- assertEquals(true, config.isEndTrimmed());
- }
-
-}
diff --git a/solr/core/src/test/org/apache/solr/internal/csv/writer/CSVFieldTest.java b/solr/core/src/test/org/apache/solr/internal/csv/writer/CSVFieldTest.java
deleted file mode 100644
index 0360d3a..0000000
--- a/solr/core/src/test/org/apache/solr/internal/csv/writer/CSVFieldTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-package org.apache.solr.internal.csv.writer;
-
-import junit.framework.TestCase;
-
-public class CSVFieldTest extends TestCase {
-
- public void testCSVField() {
- CSVField field = new CSVField();
- assertEquals(null, field.getName());
- field.setName("id");
- assertEquals("id", field.getName());
- assertEquals(0, field.getSize());
- field.setSize(10);
- assertEquals(10, field.getSize());
- field = new CSVField("name");
- assertEquals("name", field.getName());
- field = new CSVField("name", 10);
- assertEquals("name", field.getName());
- assertEquals(10, field.getSize());
- }
-
- public void testFill() {
- CSVField field = new CSVField();
- assertEquals(CSVConfig.FILLNONE, field.getFill());
- assertEquals(false, field.overrideFill());
- field.setFill(CSVConfig.FILLLEFT);
- assertEquals(true, field.overrideFill());
- assertEquals(CSVConfig.FILLLEFT, field.getFill());
- }
-}
diff --git a/solr/core/src/test/org/apache/solr/internal/csv/writer/CSVWriterTest.java b/solr/core/src/test/org/apache/solr/internal/csv/writer/CSVWriterTest.java
deleted file mode 100644
index 16178e1..0000000
--- a/solr/core/src/test/org/apache/solr/internal/csv/writer/CSVWriterTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-package org.apache.solr.internal.csv.writer;
-
-import java.io.StringWriter;
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-/**
- * The testcase for the csv writer.
- */
-public class CSVWriterTest extends TestCase {
-
- public void testCSVConfig() {
- CSVWriter writer = new CSVWriter();
- assertEquals(null, writer.getConfig());
- CSVConfig config = new CSVConfig();
- writer.setConfig(config);
- assertEquals(config, writer.getConfig());
- writer = new CSVWriter(config);
- assertEquals(config, writer.getConfig());
- }
-
- public void testWriter() {
- CSVWriter writer = new CSVWriter();
- CSVConfig config = new CSVConfig();
- config.addField(new CSVField("field1", 5));
- config.addField(new CSVField("field2", 4));
- writer.setConfig(config);
- StringWriter sw = new StringWriter();
- writer.setWriter(sw);
- Map map = new HashMap();
- map.put("field1", "12345");
- map.put("field2", "1234");
- writer.writeRecord(map);
- assertEquals("12345,1234\n",sw.toString());
- }
-}