Example usage for org.apache.solr.handler.dataimport VariableResolver VariableResolver

List of usage examples for org.apache.solr.handler.dataimport VariableResolver VariableResolver

Introduction

In this page you can find the example usage for org.apache.solr.handler.dataimport VariableResolver VariableResolver.

Prototype

public VariableResolver() 

Source Link

Usage

From source file:de.dlr.knowledgefinder.dataimport.utils.transformer.TestArrayToStringTransformer.java

License:Apache License

@SuppressWarnings("unchecked")
private void test(int testnumber) throws Exception {
    List<Map<String, String>> fields = new ArrayList<Map<String, String>>();
    fields.add(createMap("column", "target", ArrayToStringTransformer.ARRAY_SOURCE_DATA_FIELD, "target"));

    Context context = getContext(null, new VariableResolver(), null, Context.FULL_DUMP, fields, null);

    Context fakeContext = Mockito.spy(context);
    Mockito.doReturn(h.getCore()).when(fakeContext).getSolrCore();

    String strTestnumber = String.valueOf(testnumber);

    Map<String, Object> row = createMap("target", array.get("test" + strTestnumber));
    new ArrayToStringTransformer().transformRow(row, fakeContext);

    assertEquals(jointArray.get("result" + strTestnumber), row.get("target"));
}

From source file:de.dlr.knowledgefinder.dataimport.utils.transformer.TestArrayToStringTransformer.java

License:Apache License

@SuppressWarnings("unchecked")
public void testDifferentSourceAndTargetFields() throws Exception {
    List<Map<String, String>> fields = new ArrayList<Map<String, String>>();
    fields.add(createMap("column", "target", ArrayToStringTransformer.ARRAY_SOURCE_DATA_FIELD, "source"));

    Context context = getContext(null, new VariableResolver(), null, Context.FULL_DUMP, fields, null);

    Context fakeContext = Mockito.spy(context);
    Mockito.doReturn(h.getCore()).when(fakeContext).getSolrCore();

    Map<String, Object> row = createMap("source", array.get("test1"));
    new ArrayToStringTransformer().transformRow(row, fakeContext);

    assertEquals(jointArray.get("result1"), row.get("target"));
}

From source file:de.dlr.knowledgefinder.dataimport.utils.transformer.TestAuthorFormatingTransformer.java

License:Apache License

@SuppressWarnings("unchecked")
private void test(int testnumber) throws Exception {
    List<Map<String, String>> fields = new ArrayList<Map<String, String>>();
    fields.add(createMap("column", "target", AuthorFormatingTransformer.BOOL_FORMAT_DATA_FIELD, "true"));

    Context context = getContext(null, new VariableResolver(), null, Context.FULL_DUMP, fields, null);

    Context fakeContext = Mockito.spy(context);
    Mockito.doReturn(h.getCore()).when(fakeContext).getSolrCore();

    String strTestnumber = String.valueOf(testnumber);

    Map<String, Object> row = createMap("target", authorDicts.get("test" + strTestnumber));
    new AuthorFormatingTransformer().transformRow(row, fakeContext);

    Object[] result = (Object[]) row.get("target");
    Arrays.sort(result);/*from ww w .j a  va  2  s . co m*/

    assertEquals(formatedAuthors.get("result" + strTestnumber).length, result.length);
    assertArrayEquals(formatedAuthors.get("result" + strTestnumber), result);
}

From source file:de.dlr.knowledgefinder.dataimport.utils.transformer.TestCategoriesSeparatedTransformer.java

License:Apache License

@SuppressWarnings("unchecked")
public void testGetNameSimple() throws Exception {
    List<Map<String, String>> fields = new ArrayList<Map<String, String>>();
    fields.add(createMap("column", "origin", CategoriesSeparatedTransformer.CATEGORIES_FILE_FIELD,
            "categories.json", CategoriesSeparatedTransformer.CATEGORIES_SPLIT_PREFIX_FIELD, "prefix_"));

    Context context = getContext(null, new VariableResolver(), null, Context.FULL_DUMP, fields, null);

    Context fakeContext = Mockito.spy(context);
    Mockito.doReturn(h.getCore()).when(fakeContext).getSolrCore();

    Map<String, Object> row = createMap("origin", "a1");
    new CategoriesSeparatedTransformer().transformRow(row, fakeContext);

    Object[] rest1 = (Object[]) row.get("prefix_" + "category1");
    Object[] expected1 = { "a1" };
    Arrays.sort(rest1);/*from   ww  w. j  ava 2 s  . com*/

    assertEquals(rest1.length, expected1.length);
    assertTrue(Arrays.equals(rest1, expected1));
}

From source file:de.dlr.knowledgefinder.dataimport.utils.transformer.TestCategoriesSeparatedTransformer.java

License:Apache License

@SuppressWarnings("unchecked")
public void testGetNameList() throws Exception {
    List<Map<String, String>> fields = new ArrayList<Map<String, String>>();
    fields.add(createMap("column", "origin", CategoriesSeparatedTransformer.CATEGORIES_FILE_FIELD,
            "categories.json", CategoriesSeparatedTransformer.CATEGORIES_SPLIT_PREFIX_FIELD, "prefix_"));

    Context context = getContext(null, new VariableResolver(), null, Context.FULL_DUMP, fields, null);

    Context fakeContext = Mockito.spy(context);
    Mockito.doReturn(h.getCore()).when(fakeContext).getSolrCore();

    String[] categories = new String[] { "a1", "B1", "c1", "a2", "b2", "c2", "c22", "c23", "c24" };
    Map<String, Object> row = createMap("origin", categories);
    new CategoriesSeparatedTransformer().transformRow(row, fakeContext);

    Object[] rest1 = (Object[]) row.get("prefix_" + "category1");
    Object[] expected1 = cat1.toArray();
    Arrays.sort(rest1);// w  w  w . j av  a 2  s . c o m
    Arrays.sort(expected1);
    assertEquals(rest1.length, expected1.length);
    assertTrue(Arrays.equals(rest1, expected1));

    Object[] rest2 = (Object[]) row.get("prefix_" + "category2");
    Object[] expected2 = cat2.toArray();
    Arrays.sort(rest2);
    Arrays.sort(expected2);
    assertEquals(rest2.length, expected2.length);
    assertTrue(Arrays.equals(rest2, expected2));

    Object[] rest22 = (Object[]) row.get("prefix_" + "c2");
    Object[] expected22 = cat22.toArray();
    Arrays.sort(rest22);
    Arrays.sort(expected22);
    assertEquals(rest22.length, expected22.length);
    assertTrue(Arrays.equals(rest22, expected22));
}

From source file:de.dlr.knowledgefinder.dataimport.utils.transformer.TestCategoriesSeparatedTransformer.java

License:Apache License

@SuppressWarnings("unchecked")
public void testGetNameNotFound() throws Exception {
    List<Map<String, String>> fields = new ArrayList<Map<String, String>>();
    fields.add(createMap("column", "origin", CategoriesSeparatedTransformer.CATEGORIES_FILE_FIELD,
            "categories.json", CategoriesSeparatedTransformer.CATEGORIES_SPLIT_PREFIX_FIELD, "prefix_"));

    Context context = getContext(null, new VariableResolver(), null, Context.FULL_DUMP, fields, null);

    Context fakeContext = Mockito.spy(context);
    Mockito.doReturn(h.getCore()).when(fakeContext).getSolrCore();

    Map<String, Object> row = createMap("origin", "categoryXXX");
    String rowBefore = row.toString();
    new CategoriesSeparatedTransformer().transformRow(row, fakeContext);

    assertEquals(rowBefore, row.toString());
}

From source file:de.dlr.knowledgefinder.dataimport.utils.transformer.TestCategoriesSeparatedTransformer.java

License:Apache License

@SuppressWarnings("unchecked")
public void testCaseInsensitve() throws Exception {
    List<Map<String, String>> fields = new ArrayList<Map<String, String>>();
    fields.add(createMap("column", "origin", CategoriesSeparatedTransformer.CATEGORIES_FILE_FIELD,
            "categories.json", CategoriesSeparatedTransformer.CATEGORIES_SPLIT_PREFIX_FIELD, "prefix_"));

    Context context = getContext(null, new VariableResolver(), null, Context.FULL_DUMP, fields, null);

    Context fakeContext = Mockito.spy(context);
    Mockito.doReturn(h.getCore()).when(fakeContext).getSolrCore();

    String[] categories = new String[] { "A1", "b1", "c1" };
    Map<String, Object> row = createMap("origin", categories);
    new CategoriesSeparatedTransformer().transformRow(row, fakeContext);

    Object[] rest1 = (Object[]) row.get("prefix_" + "category1");
    Object[] expected1 = cat1.toArray();
    Arrays.sort(rest1);//from   w ww.jav a 2  s  .co m
    Arrays.sort(expected1);
    assertEquals(rest1.length, expected1.length);
    assertTrue(Arrays.equals(rest1, expected1));
}

From source file:de.dlr.knowledgefinder.dataimport.utils.transformer.TestDateIncompleteFormarTransformer.java

License:Apache License

/**
 * Test end date./*from   ww  w .j av  a  2 s .  c om*/
 */
@SuppressWarnings("unchecked")
public void testEndDate() {
    List<Map<String, String>> fields = new ArrayList<Map<String, String>>();
    fields.add(createMap("column", "target", DateIncompleteFormatTransformer.DATE_INCOMPLETE_REGEX, REGEX,
            DateIncompleteFormatTransformer.SRC_COL_NAME, "origin",
            DateIncompleteFormatTransformer.DATE_TIME_PARSE, DateIncompleteFormatTransformer.DATE_END));

    Context context = getContext(null, new VariableResolver(), null, Context.FULL_DUMP, fields, null);

    for (String value : valuesTestEnd.keySet()) {
        Date date = valuesTestEnd.get(value);
        Map<String, Object> row = createMap("origin", value);
        new DateIncompleteFormatTransformer().transformRow(row, context);
        Date oldDate = (Date) row.get("target");
        assertEquals(date, oldDate);
    }
}

From source file:de.dlr.knowledgefinder.dataimport.utils.transformer.TestDateIncompleteFormarTransformer.java

License:Apache License

/**
 * Test start date./*from w  w  w .ja  v  a  2s.co m*/
 */
@SuppressWarnings("unchecked")
public void testStartDate() {
    List<Map<String, String>> fields = new ArrayList<Map<String, String>>();
    fields.add(createMap("column", "target", DateIncompleteFormatTransformer.DATE_INCOMPLETE_REGEX, REGEX,
            DateIncompleteFormatTransformer.SRC_COL_NAME, "origin",
            DateIncompleteFormatTransformer.DATE_TIME_PARSE, DateIncompleteFormatTransformer.DATE_START));

    Context context = getContext(null, new VariableResolver(), null, Context.FULL_DUMP, fields, null);

    for (String value : valuesTestStart.keySet()) {
        Date date = valuesTestStart.get(value);
        Map<String, Object> row = createMap("origin", value);
        new DateIncompleteFormatTransformer().transformRow(row, context);
        Date oldDate = (Date) row.get("target");
        assertEquals(date, oldDate);
    }
}

From source file:de.dlr.knowledgefinder.dataimport.utils.transformer.TestDateIncompleteFormarTransformer.java

License:Apache License

/**
 * Test start date same column./*from w w  w.  j ava2  s .  c o  m*/
 */
@SuppressWarnings("unchecked")
public void testStartDateSameColumn() {
    List<Map<String, String>> fields = new ArrayList<Map<String, String>>();
    fields.add(createMap("column", "target", DateIncompleteFormatTransformer.DATE_INCOMPLETE_REGEX, REGEX,
            DateIncompleteFormatTransformer.DATE_TIME_PARSE, DateIncompleteFormatTransformer.DATE_START));

    Context context = getContext(null, new VariableResolver(), null, Context.FULL_DUMP, fields, null);

    for (String value : valuesTestStart.keySet()) {
        Date date = valuesTestStart.get(value);
        Map<String, Object> row = createMap("target", value);
        new DateIncompleteFormatTransformer().transformRow(row, context);
        assertEquals(date, row.get("target"));
    }
}