Skip to content

Commit

Permalink
#84 - Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
starnowski committed Dec 31, 2023
1 parent 92f511b commit 7543f7f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ public class Application {
private final Logger log = LoggerFactory.getLogger(this.getClass());
public static final String CLEAR_DATABASE_SCRIPT_PATH = "clean-database.sql";
public static final String TWEETS_SCRIPT_PATH = "tweets.sql";
public static final String TWEETS_WITH_LOCALE_SCRIPT_PATH = "tweets-with-locale.sql";
public static final String TEXT_INDEX_SCRIPT_PATH = "text-index.sql";
public static final String ENGLISH_CONFIGURATION = "english";
public static final String POLISH_CONFIGURATION = "pl_ispell";

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.starnowski.posjsonhelper.text.hibernate6.dao;

import com.github.starnowski.posjsonhelper.text.hibernate6.model.Tweet;
import com.github.starnowski.posjsonhelper.text.hibernate6.model.TweetWithLocale;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
Expand All @@ -26,22 +27,40 @@
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD;
import static org.springframework.test.context.jdbc.SqlConfig.TransactionMode.ISOLATED;

@Sql(value = {CLEAR_DATABASE_SCRIPT_PATH, TEXT_INDEX_SCRIPT_PATH},
@Sql(value = {CLEAR_DATABASE_SCRIPT_PATH, TEXT_INDEX_SCRIPT_PATH, TWEETS_WITH_LOCALE_SCRIPT_PATH},
config = @SqlConfig(transactionMode = ISOLATED),
executionPhase = BEFORE_TEST_METHOD)
@Sql(value = CLEAR_DATABASE_SCRIPT_PATH,
config = @SqlConfig(transactionMode = ISOLATED),
executionPhase = AFTER_TEST_METHOD)
@EnabledIfSystemProperty(named = "run.custom.directory.test", matches = "true")
public class TextIndexTest extends AbstractItTest {

@Autowired
private TweetDao tested;
private TweetWithLocalDao tested;

@Test
private static Stream<Arguments> provideShouldFindCorrectTweetsBySinglePlainQueryInDescription() {
return Stream.of(
Arguments.of("EV future", ENGLISH_CONFIGURATION, asList(1L)),
Arguments.of("Hydrogen", ENGLISH_CONFIGURATION, asList(2L, 3L)),
Arguments.of("Hydrogen", POLISH_CONFIGURATION, asList(4L)),
Arguments.of("Zmywarka 61 kWh", POLISH_CONFIGURATION, asList(5L, 6L, 8L))
);
}

@DisplayName("should return all ids when searching by query for english configuration' for plainto_tsquery function")
@ParameterizedTest
@MethodSource("provideShouldFindCorrectTweetsBySinglePlainQueryInDescription")
@EnabledIfSystemProperty(named = "run.custom.directory.test", matches = "true")
public void doSomeTest()
{
//TODO
public void shouldFindCorrectTweetsBySinglePlainQueryInDescription(String phrase, String configuration, List<Long> expectedIds) {

// when
List<TweetWithLocale> results = tested.findBySinglePlainQueryInDescriptionForConfiguration(phrase, configuration);

// then
assertThat(results).hasSize(expectedIds.size());
assertThat(results.stream().map(TweetWithLocale::getId).collect(toSet())).containsAll(expectedIds);
}


}
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package com.github.starnowski.posjsonhelper.text.hibernate6.dao;

import com.github.starnowski.posjsonhelper.core.HibernateContext;
import com.github.starnowski.posjsonhelper.text.hibernate6.model.TweetWithLocale;
import jakarta.persistence.EntityManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class TweetWithLocalDao {

@Autowired
private EntityManager entityManager;
@Autowired
private HibernateContext hibernateContext;

public List<TweetWithLocale> findBySinglePlainQueryInDescriptionForConfiguration(String phrase, String configuration) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
TRUNCATE tweet CASCADE;
TRUNCATE tweet CASCADE;
TRUNCATE tweet_with_locale CASCADE;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

INSERT INTO tweet_with_locale (id, title, short_content, locale) VALUES (1, 'EV cars', 'EV cars are the future', 'english');
INSERT INTO tweet_with_locale (id, title, short_content, locale) VALUES (1, 'EV cars', 'Thier are the future', 'english');
INSERT INTO tweet_with_locale (id, title, short_content, locale) VALUES (2, 'Hydrogen Cars', 'Those cars do not have luck for infrastructure', 'english');
INSERT INTO tweet_with_locale (id, title, short_content, locale) VALUES (3, 'Hydrogen batteries', 'It is great idea for storing electicity power', 'english');

Expand Down

0 comments on commit 7543f7f

Please sign in to comment.