-
Notifications
You must be signed in to change notification settings - Fork 32
test(parser): Default parser #315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
3cca8c0
b6dbe79
c9abbc5
2b72e77
bb2ff6d
630b2d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/** | ||
* | ||
* Copyright 2016-2017, Optimizely and contributors | ||
* Copyright 2016-2017, 2019, Optimizely and contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -16,15 +16,80 @@ | |
*/ | ||
package com.optimizely.ab.config.parser; | ||
|
||
import com.optimizely.ab.config.ProjectConfig; | ||
import com.optimizely.ab.internal.PropertyUtils; | ||
import org.hamcrest.CoreMatchers; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
import static com.optimizely.ab.config.DatafileProjectConfigTestUtils.*; | ||
import static com.optimizely.ab.config.DatafileProjectConfigTestUtils.validConfigJsonV4; | ||
|
||
/** | ||
* Tests for {@link DefaultConfigParser}. | ||
*/ | ||
@RunWith(Parameterized.class) | ||
public class DefaultConfigParserTest { | ||
|
||
@Parameterized.Parameters(name = "{index}") | ||
public static Collection<Object[]> data() throws IOException { | ||
return Arrays.asList(new Object[][]{ | ||
{ | ||
validConfigJsonV2(), | ||
validProjectConfigV2() | ||
}, | ||
{ | ||
validConfigJsonV3(), | ||
validProjectConfigV3() | ||
}, | ||
{ | ||
validConfigJsonV4(), | ||
validProjectConfigV4() | ||
} | ||
}); | ||
} | ||
|
||
@Parameterized.Parameter(0) | ||
public String validDatafile; | ||
|
||
@Parameterized.Parameter(1) | ||
public ProjectConfig validProjectConfig; | ||
|
||
/** | ||
* This method is to test DefaultConfigParser when different default_parser gets set. | ||
* For example: when optimizely_default_parser environment variable will be set to "GSON_CONFIG_PARSER" than | ||
* "DefaultConfigParser.getInstance()" returns "GsonConfigParser" and parse ProjectConfig using it. Also | ||
* this test will assertThat "configParser" (Provided in env variable) is instance of "GsonConfigParser.class" | ||
* | ||
* @throws Exception | ||
*/ | ||
@Test | ||
public void createThrowException() throws Exception { | ||
// FIXME - mdodsworth: hmmm, this isn't going to be the easiest thing to test | ||
public void testPropertyDefaultParser() throws Exception { | ||
String defaultParser = PropertyUtils.get("default_parser"); | ||
ConfigParser configParser = DefaultConfigParser.getInstance(); | ||
ProjectConfig actual = configParser.parseProjectConfig(validDatafile); | ||
ProjectConfig expected = validProjectConfig; | ||
verifyProjectConfig(actual, expected); | ||
if(defaultParser != null) { | ||
DefaultConfigParser.ConfigParserSupplier defaultParserSupplier = DefaultConfigParser.ConfigParserSupplier.valueOf(defaultParser); | ||
|
||
if (DefaultConfigParser.ConfigParserSupplier.GSON_CONFIG_PARSER.equals(defaultParserSupplier)) { | ||
Assert.assertThat(configParser, CoreMatchers.instanceOf(GsonConfigParser.class)); | ||
} else if (DefaultConfigParser.ConfigParserSupplier.JACKSON_CONFIG_PARSER.equals(defaultParserSupplier)) { | ||
Assert.assertThat(configParser, CoreMatchers.instanceOf(JacksonConfigParser.class)); | ||
} else if (DefaultConfigParser.ConfigParserSupplier.JSON_CONFIG_PARSER.equals(defaultParserSupplier)) { | ||
Assert.assertThat(configParser, CoreMatchers.instanceOf(JsonConfigParser.class)); | ||
} else if (DefaultConfigParser.ConfigParserSupplier.JSON_SIMPLE_CONFIG_PARSER.equals(defaultParserSupplier)) { | ||
Assert.assertThat(configParser, CoreMatchers.instanceOf(JsonSimpleConfigParser.class)); | ||
} | ||
} else { | ||
Assert.assertThat(configParser, CoreMatchers.instanceOf(GsonConfigParser.class)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we have an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, we can do that first enum that matches will be GSON_CONFIG_PARSER |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be a
switch
statement.