/*
 * Copyright 2015 Hewlett-Packard Development Company, L.P.
 * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
 */

package com.hp.autonomy.searchcomponents.idol.test;

import com.hp.autonomy.searchcomponents.core.search.GetContentRequest;
import com.hp.autonomy.searchcomponents.core.test.TestUtils;
import com.hp.autonomy.searchcomponents.idol.search.IdolGetContentRequestBuilder;
import com.hp.autonomy.searchcomponents.idol.search.IdolGetContentRequestIndexBuilder;
import com.hp.autonomy.searchcomponents.idol.search.IdolQueryRestrictions;
import com.hp.autonomy.searchcomponents.idol.search.IdolQueryRestrictionsBuilder;
import org.joda.time.DateTime;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;

@Component
public class IdolTestUtils implements TestUtils<IdolQueryRestrictions> {
    private static final String KNOWN_TEST_DATABASE = "Wookiepedia";

    @Autowired
    private ObjectFactory<IdolQueryRestrictionsBuilder> queryRestrictionsBuilderFactory;
    @Autowired
    private ObjectFactory<IdolGetContentRequestBuilder> getContentRequestBuilderFactory;
    @Autowired
    private ObjectFactory<IdolGetContentRequestIndexBuilder> getContentRequestIndexBuilderFactory;

    @Override
    public IdolQueryRestrictions buildQueryRestrictions() {
        return queryRestrictionsBuilderFactory.getObject()
                .queryText("*")
                .fieldText("")
                .database(KNOWN_TEST_DATABASE)
                .minDate(null)
                .maxDate(DateTime.now())
                .minScore(0)
                .languageType(null)
                .anyLanguage(true)
                .stateMatchIds(Collections.emptyList())
                .stateDontMatchIds(Collections.emptyList())
                .build();
    }

    @Override
    public <RC extends GetContentRequest<?>> RC buildGetContentRequest(final String reference) {
        @SuppressWarnings("unchecked")
        final RC getContentRequest = (RC) getContentRequestBuilderFactory.getObject()
                .indexAndReferences(getContentRequestIndexBuilderFactory.getObject()
                        .index(KNOWN_TEST_DATABASE)
                        .reference(reference)
                        .build())
                .build();
        return getContentRequest;
    }
}

@@ -838,16 +838,65 @@
 owired;%0A
+import org.springframework.core.env.Environment;%0A
 import o
@@ -968,16 +968,50 @@
 tions;%0A%0A
+@SuppressWarnings(%22WeakerAccess%22)%0A
 @Compone
@@ -1091,22 +1091,94 @@
  %7B%0A    p
-rivate
+ublic static final String TEST_DATABASE_PROPERTY = %22test.database%22;%0A    public
  static 
@@ -1190,21 +1190,23 @@
  String 
-KNOWN
+DEFAULT
 _TEST_DA
@@ -1551,16 +1551,68 @@
 Factory;
+%0A    @Autowired%0A    private Environment environment;
 %0A%0A    @O
@@ -1827,21 +1827,71 @@
 atabase(
-KNOWN
+environment.getProperty(TEST_DATABASE_PROPERTY, DEFAULT
 _TEST_DA
@@ -1889,32 +1889,33 @@
 T_TEST_DATABASE)
+)
 %0A               
@@ -2576,13 +2576,63 @@
 dex(
-KNOWN
+environment.getProperty(TEST_DATABASE_PROPERTY, DEFAULT
 _TES
@@ -2642,16 +2642,17 @@
 ATABASE)
+)
 %0A       

Allow setting IT database from system properties.