generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added statistics search implementation v.2
- Loading branch information
Showing
11 changed files
with
207 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/softserve/teachua/utils/validations/QueryStringValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.softserve.teachua.utils.validations; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class QueryStringValidator { | ||
private static final int MIN_QUERY_LENGTH = 4; | ||
private static final int MAX_QUERY_LENGTH = 50; | ||
|
||
public boolean isValid(String queryString, long elemCount) { | ||
if (queryString == null || queryString.trim().isEmpty()) { | ||
return false; | ||
} | ||
|
||
if (elemCount < 0) { | ||
return false; | ||
} | ||
|
||
if (queryString.length() < MIN_QUERY_LENGTH || queryString.length() > MAX_QUERY_LENGTH) { | ||
return false; | ||
} | ||
|
||
if (!queryString.matches("^[a-zA-Z0-9\\s]+$")) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/test/java/com/softserve/teachua/config/SearchStatisticsPropertiesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.softserve.teachua.config; | ||
|
||
import java.util.Date; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.BeanCreationException; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
|
||
@EnableConfigurationProperties(SearchStatisticsProperties.class) | ||
class SearchStatisticsPropertiesTest { | ||
|
||
private SearchStatisticsProperties properties; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
properties = new SearchStatisticsProperties(); | ||
} | ||
|
||
@Test | ||
void testToCache() { | ||
properties.setToCache(true); | ||
assertTrue(properties.isToCache()); | ||
|
||
properties.setToCache(false); | ||
assertFalse(properties.isToCache()); | ||
} | ||
|
||
@Test | ||
void testMaxTime() { | ||
properties.setMaxTime("2023-10-09 12:00:00"); | ||
assertEquals("2023-10-09 12:00:00", properties.getMaxTime()); | ||
} | ||
|
||
@Test | ||
void testMaxNumber() { | ||
properties.setMaxNumber(42); | ||
assertEquals(42, properties.getMaxNumber()); | ||
} | ||
|
||
@Test | ||
void testValidateAndParseMaxTimeValid() { | ||
properties.setMaxTime("2023-10-09 12:00:00"); | ||
Date result = properties.validateAndParseMaxTime(); | ||
assertNotNull(result); | ||
} | ||
|
||
@Test | ||
void testValidateAndParseMaxTimeInvalid() { | ||
properties.setMaxTime("invalid-date-format"); | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
properties.validateAndParseMaxTime(); | ||
}); | ||
} | ||
|
||
@Test | ||
void testValidateAndParseMaxTimeNull() { | ||
properties.setMaxTime("23324:323-122"); | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
properties.validateAndParseMaxTime(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.