Addded blog property test.
This commit is contained in:
parent
bc12aded51
commit
a7f6b6a6c4
1 changed files with 19 additions and 9 deletions
|
@ -51,10 +51,9 @@ import java.util.logging.ConsoleHandler
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
import javax.servlet.http.HttpServletRequest
|
import javax.servlet.http.HttpServletRequest
|
||||||
|
|
||||||
fun getKeys(): Array<String> {
|
fun getKey(key: String): String {
|
||||||
var apiKey = System.getenv("AKISMET_API_KEY") ?: ""
|
var value = System.getenv(key) ?: ""
|
||||||
var blog = System.getenv("AKISMET_BLOG") ?: ""
|
if (value.isBlank()) {
|
||||||
if (apiKey.isBlank()) {
|
|
||||||
val localProps = File("local.properties")
|
val localProps = File("local.properties")
|
||||||
if (localProps.exists())
|
if (localProps.exists())
|
||||||
localProps.apply {
|
localProps.apply {
|
||||||
|
@ -62,17 +61,20 @@ fun getKeys(): Array<String> {
|
||||||
FileInputStream(this).use { fis ->
|
FileInputStream(this).use { fis ->
|
||||||
Properties().apply {
|
Properties().apply {
|
||||||
load(fis)
|
load(fis)
|
||||||
apiKey = getProperty("AKISMET_API_KEY", "")
|
value = getProperty(key, "")
|
||||||
blog = getProperty("AKISMET_BLOG", "")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return arrayOf(apiKey, blog)
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AKISMET_API_KEY and AKISMET_BLOG should be in env vars or local.properties
|
||||||
|
*/
|
||||||
class AkismetTest {
|
class AkismetTest {
|
||||||
|
private val blog = getKey("AKISMET_BLOG")
|
||||||
private val userIp = "127.0.0.1"
|
private val userIp = "127.0.0.1"
|
||||||
private val userAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6"
|
private val userAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6"
|
||||||
private val referrer = "http://www.google.com"
|
private val referrer = "http://www.google.com"
|
||||||
|
@ -84,7 +86,7 @@ class AkismetTest {
|
||||||
private val content = "It means a lot that you would take the time to review our software. Thanks again."
|
private val content = "It means a lot that you would take the time to review our software. Thanks again."
|
||||||
private val spamAuthor = "viagra-test-123"
|
private val spamAuthor = "viagra-test-123"
|
||||||
private val spamEmail = "akismet-guaranteed-spam@example.com"
|
private val spamEmail = "akismet-guaranteed-spam@example.com"
|
||||||
private val akismet = Akismet(getKeys()[0], getKeys()[1])
|
private val akismet = Akismet(getKey("AKISMET_API_KEY"), blog)
|
||||||
private val request = Mockito.mock(HttpServletRequest::class.java)
|
private val request = Mockito.mock(HttpServletRequest::class.java)
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
|
@ -105,7 +107,7 @@ class AkismetTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun constructorTest() {
|
fun constructorsTest() {
|
||||||
expectThrows(IllegalArgumentException::class.java) {
|
expectThrows(IllegalArgumentException::class.java) {
|
||||||
Akismet("123456789012", "http://www.foo.com/")
|
Akismet("123456789012", "http://www.foo.com/")
|
||||||
Akismet("", "http://www.foo.com/")
|
Akismet("", "http://www.foo.com/")
|
||||||
|
@ -113,6 +115,14 @@ class AkismetTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun blogPropertyTest() {
|
||||||
|
expectThrows(IllegalArgumentException::class.java) {
|
||||||
|
akismet.blog = ""
|
||||||
|
}
|
||||||
|
assertEquals(akismet.blog, blog, "valid property")
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun verifyKeyTest() {
|
fun verifyKeyTest() {
|
||||||
assertFalse(akismet.isVerifiedKey, "isVerifiedKey -> false")
|
assertFalse(akismet.isVerifiedKey, "isVerifiedKey -> false")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue