repo_name stringlengths 7 104 | file_path stringlengths 13 198 | context stringlengths 67 7.15k | import_statement stringlengths 16 4.43k | code stringlengths 40 6.98k | prompt stringlengths 227 8.27k | next_line stringlengths 8 795 |
|---|---|---|---|---|---|---|
TNG/property-loader | src/test/java/com/tngtech/propertyloader/PropertyLoaderTest.java | // Path: src/main/java/com/tngtech/propertyloader/exception/PropertyLoaderException.java
// public class PropertyLoaderException extends RuntimeException {
//
// public PropertyLoaderException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/helpers/HostsHelper.java
// public class HostsHelper {
//
// public List<String> getLocalHostNames() {
// Set<String> hostSet = new HashSet<String>();
//
// for (InetAddress host : getLocalHosts()) {
// hostSet.add(host.getHostName());
// }
//
// List<String> hostNames = new ArrayList<String>(hostSet);
// Collections.sort(hostNames);
//
// return hostNames;
// }
//
// private InetAddress[] getLocalHosts() {
// InetAddress in;
//
// try {
// in = InetAddress.getLocalHost();
// } catch (UnknownHostException uE) {
// return new InetAddress[0];
// }
//
// try {
// return InetAddress.getAllByName(in.getHostName());
// } catch (UnknownHostException uE) {
// return new InetAddress[]{in};
// }
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/helpers/PropertyFileNameHelper.java
// public class PropertyFileNameHelper {
// public List<String> getFileNames(Collection<String> baseNames, Collection<String> suffixes, String fileExtension) {
// List<String> fileNameList = new ArrayList<String>();
// for (String baseName : baseNames) {
// fileNameList.add(baseName + "." + fileExtension);
// for (String suffix : suffixes) {
// fileNameList.add(baseName + "." + suffix + "." + fileExtension);
// }
// }
// return fileNameList;
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/interfaces/PropertyLoaderOpener.java
// public interface PropertyLoaderOpener {
//
// /**
// * Attempt to find and open some property file.
// *
// * @param fileName A relative filename (using '/' as directory separator on all platforms)
// * @return An input stream reading from that file, or null if the file could not be found
// */
// InputStream open(String fileName);
// }
| import com.tngtech.propertyloader.exception.PropertyLoaderException;
import com.tngtech.propertyloader.impl.*;
import com.tngtech.propertyloader.impl.helpers.HostsHelper;
import com.tngtech.propertyloader.impl.helpers.PropertyFileNameHelper;
import com.tngtech.propertyloader.impl.interfaces.PropertyLoaderOpener;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.Stack;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; | public void testWithWarnOnSurroundingWhitespace() {
assertEquals(propertyLoader, propertyLoader.withWarnOnSurroundingWhitespace());
verify(propertyFilter).withWarnOnSurroundingWhitespace();
}
@Test
public void testLoadFromBaseName_Calls_loadPropertiesFromBaseNameList_And_filterProperties() {
propertyLoader.load("file");
verify(propertyLoaderFactory).getEmptyFileNameStack();
verify(propertyLoaderFactory).getEmptyProperties();
verify(propertyFilter).getFilters();
}
@Test
public void testLoadFromBaseNameList_Calls_loadPropertiesFromBaseNameList_And_filterProperties() {
String[] baseNames = {"file"};
propertyLoader.load(baseNames);
verify(propertyLoaderFactory).getEmptyFileNameStack();
verify(propertyLoaderFactory).getEmptyProperties();
verify(propertyFilter).getFilters();
}
@Test
public void testLoad_Calls_loadPropertiesFromBaseNameList_And_filterProperties() {
propertyLoader.load();
verify(propertyLoaderFactory).getEmptyFileNameStack();
verify(propertyLoaderFactory).getEmptyProperties();
verify(propertyFilter).getFilters();
}
| // Path: src/main/java/com/tngtech/propertyloader/exception/PropertyLoaderException.java
// public class PropertyLoaderException extends RuntimeException {
//
// public PropertyLoaderException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/helpers/HostsHelper.java
// public class HostsHelper {
//
// public List<String> getLocalHostNames() {
// Set<String> hostSet = new HashSet<String>();
//
// for (InetAddress host : getLocalHosts()) {
// hostSet.add(host.getHostName());
// }
//
// List<String> hostNames = new ArrayList<String>(hostSet);
// Collections.sort(hostNames);
//
// return hostNames;
// }
//
// private InetAddress[] getLocalHosts() {
// InetAddress in;
//
// try {
// in = InetAddress.getLocalHost();
// } catch (UnknownHostException uE) {
// return new InetAddress[0];
// }
//
// try {
// return InetAddress.getAllByName(in.getHostName());
// } catch (UnknownHostException uE) {
// return new InetAddress[]{in};
// }
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/helpers/PropertyFileNameHelper.java
// public class PropertyFileNameHelper {
// public List<String> getFileNames(Collection<String> baseNames, Collection<String> suffixes, String fileExtension) {
// List<String> fileNameList = new ArrayList<String>();
// for (String baseName : baseNames) {
// fileNameList.add(baseName + "." + fileExtension);
// for (String suffix : suffixes) {
// fileNameList.add(baseName + "." + suffix + "." + fileExtension);
// }
// }
// return fileNameList;
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/interfaces/PropertyLoaderOpener.java
// public interface PropertyLoaderOpener {
//
// /**
// * Attempt to find and open some property file.
// *
// * @param fileName A relative filename (using '/' as directory separator on all platforms)
// * @return An input stream reading from that file, or null if the file could not be found
// */
// InputStream open(String fileName);
// }
// Path: src/test/java/com/tngtech/propertyloader/PropertyLoaderTest.java
import com.tngtech.propertyloader.exception.PropertyLoaderException;
import com.tngtech.propertyloader.impl.*;
import com.tngtech.propertyloader.impl.helpers.HostsHelper;
import com.tngtech.propertyloader.impl.helpers.PropertyFileNameHelper;
import com.tngtech.propertyloader.impl.interfaces.PropertyLoaderOpener;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.Stack;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public void testWithWarnOnSurroundingWhitespace() {
assertEquals(propertyLoader, propertyLoader.withWarnOnSurroundingWhitespace());
verify(propertyFilter).withWarnOnSurroundingWhitespace();
}
@Test
public void testLoadFromBaseName_Calls_loadPropertiesFromBaseNameList_And_filterProperties() {
propertyLoader.load("file");
verify(propertyLoaderFactory).getEmptyFileNameStack();
verify(propertyLoaderFactory).getEmptyProperties();
verify(propertyFilter).getFilters();
}
@Test
public void testLoadFromBaseNameList_Calls_loadPropertiesFromBaseNameList_And_filterProperties() {
String[] baseNames = {"file"};
propertyLoader.load(baseNames);
verify(propertyLoaderFactory).getEmptyFileNameStack();
verify(propertyLoaderFactory).getEmptyProperties();
verify(propertyFilter).getFilters();
}
@Test
public void testLoad_Calls_loadPropertiesFromBaseNameList_And_filterProperties() {
propertyLoader.load();
verify(propertyLoaderFactory).getEmptyFileNameStack();
verify(propertyLoaderFactory).getEmptyProperties();
verify(propertyFilter).getFilters();
}
| @Test(expected = PropertyLoaderException.class) |
TNG/property-loader | src/test/java/com/tngtech/propertyloader/impl/DefaultPropertyFilterContainerTest.java | // Path: src/main/java/com/tngtech/propertyloader/impl/filters/EnvironmentResolvingFilter.java
// public class EnvironmentResolvingFilter extends ValueModifyingFilter {
//
// private static final Logger log = LoggerFactory.getLogger(EnvironmentResolvingFilter.class);
//
// private static final Pattern PATTERN = Pattern.compile("\\$ENV\\{(.*)\\}");
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// Matcher matcher = PATTERN.matcher(value);
// if (matcher.matches()) {
// value = getenv(matcher.group(1));
// if (value == null) {
// log.warn("There is no system property called '{}'.", matcher.group(1));
// }
// }
// return value;
// }
//
// protected String getenv(String key) {
// return System.getenv(key);
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/ThrowIfPropertyHasToBeDefined.java
// public class ThrowIfPropertyHasToBeDefined implements PropertyLoaderFilter {
//
// public static final String HAS_TO_BE_DEFINED = "<HAS_TO_BE_DEFINED>";
//
// @Override
// public void filter(Properties properties) {
// for (Map.Entry<Object, Object> entry : properties.entrySet()) {
// String key = entry.getKey().toString();
// String value = entry.getValue().toString();
// if (HAS_TO_BE_DEFINED.equals(value)) {
// StringBuilder sb = new StringBuilder();
// sb.append("\n" + "Configuration incomplete: property ").append(key).append(" is still mapped to ").append(value);
// properties.remove(entry.getKey());
// try {
// filter(properties);
// } catch (ThrowIfPropertyHasToBeDefinedException e) {
// sb.append(e.getMessage());
// }
// throw new ThrowIfPropertyHasToBeDefinedException(sb.toString());
// }
// }
// }
//
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/VariableResolvingFilter.java
// public class VariableResolvingFilter extends ValueModifyingFilter {
//
// private static final String VARIABLE_PREFIX = "${";
// private static final String VARIABLE_SUFFIX = "}";
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// if (!value.contains(VARIABLE_PREFIX)) {
// return value;
// }
//
// int startIndex = value.lastIndexOf(VARIABLE_PREFIX);
// int endIndex = value.indexOf(VARIABLE_SUFFIX, startIndex + VARIABLE_PREFIX.length());
//
// String prefix = value.substring(0, startIndex);
// String variableName = value.substring(startIndex + VARIABLE_PREFIX.length(), endIndex);
// String suffix = value.substring(endIndex + VARIABLE_SUFFIX.length());
//
// String replacement = findReplacement(variableName, properties);
// if (replacement == null) {
// throw new VariableResolvingFilterException("Error during variable resolution: No value found for variable " + variableName);
// }
// String replacedValue = prefix + replacement + suffix;
//
// // In case this is a "${deeply${nested}}${variable}", look for something to resolve again
// return filterValue(key, replacedValue, properties);
// }
//
// private String findReplacement(String variableName, Properties properties) {
// String result = properties.getProperty(variableName);
// if (result != null) {
// return result;
// }
// return System.getProperty(variableName);
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/WarnOnSurroundingWhitespace.java
// public class WarnOnSurroundingWhitespace extends ValueModifyingFilter {
//
// private static final Logger log = LoggerFactory.getLogger(WarnOnSurroundingWhitespace.class);
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// // don't show lines that end with "\n", that is ok and sometimes needed
// if (!value.trim().equals(value) && !value.endsWith("\n")) {
// log.warn("Key '{}' mapped to '{}', containing whitespace at the end. You probably do not want this.", key, value);
// }
//
// return value;
// }
// }
| import com.tngtech.propertyloader.impl.filters.EnvironmentResolvingFilter;
import com.tngtech.propertyloader.impl.filters.ThrowIfPropertyHasToBeDefined;
import com.tngtech.propertyloader.impl.filters.VariableResolvingFilter;
import com.tngtech.propertyloader.impl.filters.WarnOnSurroundingWhitespace;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.net.MalformedURLException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when; | package com.tngtech.propertyloader.impl;
@RunWith(MockitoJUnitRunner.class)
public class DefaultPropertyFilterContainerTest {
@InjectMocks
private DefaultPropertyFilterContainer propertyFilter;
@Mock
private PropertyLoaderFactory propertyLoaderFactory;
@Mock | // Path: src/main/java/com/tngtech/propertyloader/impl/filters/EnvironmentResolvingFilter.java
// public class EnvironmentResolvingFilter extends ValueModifyingFilter {
//
// private static final Logger log = LoggerFactory.getLogger(EnvironmentResolvingFilter.class);
//
// private static final Pattern PATTERN = Pattern.compile("\\$ENV\\{(.*)\\}");
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// Matcher matcher = PATTERN.matcher(value);
// if (matcher.matches()) {
// value = getenv(matcher.group(1));
// if (value == null) {
// log.warn("There is no system property called '{}'.", matcher.group(1));
// }
// }
// return value;
// }
//
// protected String getenv(String key) {
// return System.getenv(key);
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/ThrowIfPropertyHasToBeDefined.java
// public class ThrowIfPropertyHasToBeDefined implements PropertyLoaderFilter {
//
// public static final String HAS_TO_BE_DEFINED = "<HAS_TO_BE_DEFINED>";
//
// @Override
// public void filter(Properties properties) {
// for (Map.Entry<Object, Object> entry : properties.entrySet()) {
// String key = entry.getKey().toString();
// String value = entry.getValue().toString();
// if (HAS_TO_BE_DEFINED.equals(value)) {
// StringBuilder sb = new StringBuilder();
// sb.append("\n" + "Configuration incomplete: property ").append(key).append(" is still mapped to ").append(value);
// properties.remove(entry.getKey());
// try {
// filter(properties);
// } catch (ThrowIfPropertyHasToBeDefinedException e) {
// sb.append(e.getMessage());
// }
// throw new ThrowIfPropertyHasToBeDefinedException(sb.toString());
// }
// }
// }
//
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/VariableResolvingFilter.java
// public class VariableResolvingFilter extends ValueModifyingFilter {
//
// private static final String VARIABLE_PREFIX = "${";
// private static final String VARIABLE_SUFFIX = "}";
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// if (!value.contains(VARIABLE_PREFIX)) {
// return value;
// }
//
// int startIndex = value.lastIndexOf(VARIABLE_PREFIX);
// int endIndex = value.indexOf(VARIABLE_SUFFIX, startIndex + VARIABLE_PREFIX.length());
//
// String prefix = value.substring(0, startIndex);
// String variableName = value.substring(startIndex + VARIABLE_PREFIX.length(), endIndex);
// String suffix = value.substring(endIndex + VARIABLE_SUFFIX.length());
//
// String replacement = findReplacement(variableName, properties);
// if (replacement == null) {
// throw new VariableResolvingFilterException("Error during variable resolution: No value found for variable " + variableName);
// }
// String replacedValue = prefix + replacement + suffix;
//
// // In case this is a "${deeply${nested}}${variable}", look for something to resolve again
// return filterValue(key, replacedValue, properties);
// }
//
// private String findReplacement(String variableName, Properties properties) {
// String result = properties.getProperty(variableName);
// if (result != null) {
// return result;
// }
// return System.getProperty(variableName);
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/WarnOnSurroundingWhitespace.java
// public class WarnOnSurroundingWhitespace extends ValueModifyingFilter {
//
// private static final Logger log = LoggerFactory.getLogger(WarnOnSurroundingWhitespace.class);
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// // don't show lines that end with "\n", that is ok and sometimes needed
// if (!value.trim().equals(value) && !value.endsWith("\n")) {
// log.warn("Key '{}' mapped to '{}', containing whitespace at the end. You probably do not want this.", key, value);
// }
//
// return value;
// }
// }
// Path: src/test/java/com/tngtech/propertyloader/impl/DefaultPropertyFilterContainerTest.java
import com.tngtech.propertyloader.impl.filters.EnvironmentResolvingFilter;
import com.tngtech.propertyloader.impl.filters.ThrowIfPropertyHasToBeDefined;
import com.tngtech.propertyloader.impl.filters.VariableResolvingFilter;
import com.tngtech.propertyloader.impl.filters.WarnOnSurroundingWhitespace;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.net.MalformedURLException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
package com.tngtech.propertyloader.impl;
@RunWith(MockitoJUnitRunner.class)
public class DefaultPropertyFilterContainerTest {
@InjectMocks
private DefaultPropertyFilterContainer propertyFilter;
@Mock
private PropertyLoaderFactory propertyLoaderFactory;
@Mock | private VariableResolvingFilter variableResolvingFilter; |
TNG/property-loader | src/test/java/com/tngtech/propertyloader/impl/DefaultPropertyFilterContainerTest.java | // Path: src/main/java/com/tngtech/propertyloader/impl/filters/EnvironmentResolvingFilter.java
// public class EnvironmentResolvingFilter extends ValueModifyingFilter {
//
// private static final Logger log = LoggerFactory.getLogger(EnvironmentResolvingFilter.class);
//
// private static final Pattern PATTERN = Pattern.compile("\\$ENV\\{(.*)\\}");
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// Matcher matcher = PATTERN.matcher(value);
// if (matcher.matches()) {
// value = getenv(matcher.group(1));
// if (value == null) {
// log.warn("There is no system property called '{}'.", matcher.group(1));
// }
// }
// return value;
// }
//
// protected String getenv(String key) {
// return System.getenv(key);
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/ThrowIfPropertyHasToBeDefined.java
// public class ThrowIfPropertyHasToBeDefined implements PropertyLoaderFilter {
//
// public static final String HAS_TO_BE_DEFINED = "<HAS_TO_BE_DEFINED>";
//
// @Override
// public void filter(Properties properties) {
// for (Map.Entry<Object, Object> entry : properties.entrySet()) {
// String key = entry.getKey().toString();
// String value = entry.getValue().toString();
// if (HAS_TO_BE_DEFINED.equals(value)) {
// StringBuilder sb = new StringBuilder();
// sb.append("\n" + "Configuration incomplete: property ").append(key).append(" is still mapped to ").append(value);
// properties.remove(entry.getKey());
// try {
// filter(properties);
// } catch (ThrowIfPropertyHasToBeDefinedException e) {
// sb.append(e.getMessage());
// }
// throw new ThrowIfPropertyHasToBeDefinedException(sb.toString());
// }
// }
// }
//
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/VariableResolvingFilter.java
// public class VariableResolvingFilter extends ValueModifyingFilter {
//
// private static final String VARIABLE_PREFIX = "${";
// private static final String VARIABLE_SUFFIX = "}";
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// if (!value.contains(VARIABLE_PREFIX)) {
// return value;
// }
//
// int startIndex = value.lastIndexOf(VARIABLE_PREFIX);
// int endIndex = value.indexOf(VARIABLE_SUFFIX, startIndex + VARIABLE_PREFIX.length());
//
// String prefix = value.substring(0, startIndex);
// String variableName = value.substring(startIndex + VARIABLE_PREFIX.length(), endIndex);
// String suffix = value.substring(endIndex + VARIABLE_SUFFIX.length());
//
// String replacement = findReplacement(variableName, properties);
// if (replacement == null) {
// throw new VariableResolvingFilterException("Error during variable resolution: No value found for variable " + variableName);
// }
// String replacedValue = prefix + replacement + suffix;
//
// // In case this is a "${deeply${nested}}${variable}", look for something to resolve again
// return filterValue(key, replacedValue, properties);
// }
//
// private String findReplacement(String variableName, Properties properties) {
// String result = properties.getProperty(variableName);
// if (result != null) {
// return result;
// }
// return System.getProperty(variableName);
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/WarnOnSurroundingWhitespace.java
// public class WarnOnSurroundingWhitespace extends ValueModifyingFilter {
//
// private static final Logger log = LoggerFactory.getLogger(WarnOnSurroundingWhitespace.class);
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// // don't show lines that end with "\n", that is ok and sometimes needed
// if (!value.trim().equals(value) && !value.endsWith("\n")) {
// log.warn("Key '{}' mapped to '{}', containing whitespace at the end. You probably do not want this.", key, value);
// }
//
// return value;
// }
// }
| import com.tngtech.propertyloader.impl.filters.EnvironmentResolvingFilter;
import com.tngtech.propertyloader.impl.filters.ThrowIfPropertyHasToBeDefined;
import com.tngtech.propertyloader.impl.filters.VariableResolvingFilter;
import com.tngtech.propertyloader.impl.filters.WarnOnSurroundingWhitespace;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.net.MalformedURLException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when; | package com.tngtech.propertyloader.impl;
@RunWith(MockitoJUnitRunner.class)
public class DefaultPropertyFilterContainerTest {
@InjectMocks
private DefaultPropertyFilterContainer propertyFilter;
@Mock
private PropertyLoaderFactory propertyLoaderFactory;
@Mock
private VariableResolvingFilter variableResolvingFilter;
@Mock | // Path: src/main/java/com/tngtech/propertyloader/impl/filters/EnvironmentResolvingFilter.java
// public class EnvironmentResolvingFilter extends ValueModifyingFilter {
//
// private static final Logger log = LoggerFactory.getLogger(EnvironmentResolvingFilter.class);
//
// private static final Pattern PATTERN = Pattern.compile("\\$ENV\\{(.*)\\}");
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// Matcher matcher = PATTERN.matcher(value);
// if (matcher.matches()) {
// value = getenv(matcher.group(1));
// if (value == null) {
// log.warn("There is no system property called '{}'.", matcher.group(1));
// }
// }
// return value;
// }
//
// protected String getenv(String key) {
// return System.getenv(key);
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/ThrowIfPropertyHasToBeDefined.java
// public class ThrowIfPropertyHasToBeDefined implements PropertyLoaderFilter {
//
// public static final String HAS_TO_BE_DEFINED = "<HAS_TO_BE_DEFINED>";
//
// @Override
// public void filter(Properties properties) {
// for (Map.Entry<Object, Object> entry : properties.entrySet()) {
// String key = entry.getKey().toString();
// String value = entry.getValue().toString();
// if (HAS_TO_BE_DEFINED.equals(value)) {
// StringBuilder sb = new StringBuilder();
// sb.append("\n" + "Configuration incomplete: property ").append(key).append(" is still mapped to ").append(value);
// properties.remove(entry.getKey());
// try {
// filter(properties);
// } catch (ThrowIfPropertyHasToBeDefinedException e) {
// sb.append(e.getMessage());
// }
// throw new ThrowIfPropertyHasToBeDefinedException(sb.toString());
// }
// }
// }
//
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/VariableResolvingFilter.java
// public class VariableResolvingFilter extends ValueModifyingFilter {
//
// private static final String VARIABLE_PREFIX = "${";
// private static final String VARIABLE_SUFFIX = "}";
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// if (!value.contains(VARIABLE_PREFIX)) {
// return value;
// }
//
// int startIndex = value.lastIndexOf(VARIABLE_PREFIX);
// int endIndex = value.indexOf(VARIABLE_SUFFIX, startIndex + VARIABLE_PREFIX.length());
//
// String prefix = value.substring(0, startIndex);
// String variableName = value.substring(startIndex + VARIABLE_PREFIX.length(), endIndex);
// String suffix = value.substring(endIndex + VARIABLE_SUFFIX.length());
//
// String replacement = findReplacement(variableName, properties);
// if (replacement == null) {
// throw new VariableResolvingFilterException("Error during variable resolution: No value found for variable " + variableName);
// }
// String replacedValue = prefix + replacement + suffix;
//
// // In case this is a "${deeply${nested}}${variable}", look for something to resolve again
// return filterValue(key, replacedValue, properties);
// }
//
// private String findReplacement(String variableName, Properties properties) {
// String result = properties.getProperty(variableName);
// if (result != null) {
// return result;
// }
// return System.getProperty(variableName);
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/WarnOnSurroundingWhitespace.java
// public class WarnOnSurroundingWhitespace extends ValueModifyingFilter {
//
// private static final Logger log = LoggerFactory.getLogger(WarnOnSurroundingWhitespace.class);
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// // don't show lines that end with "\n", that is ok and sometimes needed
// if (!value.trim().equals(value) && !value.endsWith("\n")) {
// log.warn("Key '{}' mapped to '{}', containing whitespace at the end. You probably do not want this.", key, value);
// }
//
// return value;
// }
// }
// Path: src/test/java/com/tngtech/propertyloader/impl/DefaultPropertyFilterContainerTest.java
import com.tngtech.propertyloader.impl.filters.EnvironmentResolvingFilter;
import com.tngtech.propertyloader.impl.filters.ThrowIfPropertyHasToBeDefined;
import com.tngtech.propertyloader.impl.filters.VariableResolvingFilter;
import com.tngtech.propertyloader.impl.filters.WarnOnSurroundingWhitespace;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.net.MalformedURLException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
package com.tngtech.propertyloader.impl;
@RunWith(MockitoJUnitRunner.class)
public class DefaultPropertyFilterContainerTest {
@InjectMocks
private DefaultPropertyFilterContainer propertyFilter;
@Mock
private PropertyLoaderFactory propertyLoaderFactory;
@Mock
private VariableResolvingFilter variableResolvingFilter;
@Mock | private EnvironmentResolvingFilter environmentResolvingFilter; |
TNG/property-loader | src/test/java/com/tngtech/propertyloader/impl/DefaultPropertyFilterContainerTest.java | // Path: src/main/java/com/tngtech/propertyloader/impl/filters/EnvironmentResolvingFilter.java
// public class EnvironmentResolvingFilter extends ValueModifyingFilter {
//
// private static final Logger log = LoggerFactory.getLogger(EnvironmentResolvingFilter.class);
//
// private static final Pattern PATTERN = Pattern.compile("\\$ENV\\{(.*)\\}");
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// Matcher matcher = PATTERN.matcher(value);
// if (matcher.matches()) {
// value = getenv(matcher.group(1));
// if (value == null) {
// log.warn("There is no system property called '{}'.", matcher.group(1));
// }
// }
// return value;
// }
//
// protected String getenv(String key) {
// return System.getenv(key);
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/ThrowIfPropertyHasToBeDefined.java
// public class ThrowIfPropertyHasToBeDefined implements PropertyLoaderFilter {
//
// public static final String HAS_TO_BE_DEFINED = "<HAS_TO_BE_DEFINED>";
//
// @Override
// public void filter(Properties properties) {
// for (Map.Entry<Object, Object> entry : properties.entrySet()) {
// String key = entry.getKey().toString();
// String value = entry.getValue().toString();
// if (HAS_TO_BE_DEFINED.equals(value)) {
// StringBuilder sb = new StringBuilder();
// sb.append("\n" + "Configuration incomplete: property ").append(key).append(" is still mapped to ").append(value);
// properties.remove(entry.getKey());
// try {
// filter(properties);
// } catch (ThrowIfPropertyHasToBeDefinedException e) {
// sb.append(e.getMessage());
// }
// throw new ThrowIfPropertyHasToBeDefinedException(sb.toString());
// }
// }
// }
//
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/VariableResolvingFilter.java
// public class VariableResolvingFilter extends ValueModifyingFilter {
//
// private static final String VARIABLE_PREFIX = "${";
// private static final String VARIABLE_SUFFIX = "}";
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// if (!value.contains(VARIABLE_PREFIX)) {
// return value;
// }
//
// int startIndex = value.lastIndexOf(VARIABLE_PREFIX);
// int endIndex = value.indexOf(VARIABLE_SUFFIX, startIndex + VARIABLE_PREFIX.length());
//
// String prefix = value.substring(0, startIndex);
// String variableName = value.substring(startIndex + VARIABLE_PREFIX.length(), endIndex);
// String suffix = value.substring(endIndex + VARIABLE_SUFFIX.length());
//
// String replacement = findReplacement(variableName, properties);
// if (replacement == null) {
// throw new VariableResolvingFilterException("Error during variable resolution: No value found for variable " + variableName);
// }
// String replacedValue = prefix + replacement + suffix;
//
// // In case this is a "${deeply${nested}}${variable}", look for something to resolve again
// return filterValue(key, replacedValue, properties);
// }
//
// private String findReplacement(String variableName, Properties properties) {
// String result = properties.getProperty(variableName);
// if (result != null) {
// return result;
// }
// return System.getProperty(variableName);
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/WarnOnSurroundingWhitespace.java
// public class WarnOnSurroundingWhitespace extends ValueModifyingFilter {
//
// private static final Logger log = LoggerFactory.getLogger(WarnOnSurroundingWhitespace.class);
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// // don't show lines that end with "\n", that is ok and sometimes needed
// if (!value.trim().equals(value) && !value.endsWith("\n")) {
// log.warn("Key '{}' mapped to '{}', containing whitespace at the end. You probably do not want this.", key, value);
// }
//
// return value;
// }
// }
| import com.tngtech.propertyloader.impl.filters.EnvironmentResolvingFilter;
import com.tngtech.propertyloader.impl.filters.ThrowIfPropertyHasToBeDefined;
import com.tngtech.propertyloader.impl.filters.VariableResolvingFilter;
import com.tngtech.propertyloader.impl.filters.WarnOnSurroundingWhitespace;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.net.MalformedURLException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when; | package com.tngtech.propertyloader.impl;
@RunWith(MockitoJUnitRunner.class)
public class DefaultPropertyFilterContainerTest {
@InjectMocks
private DefaultPropertyFilterContainer propertyFilter;
@Mock
private PropertyLoaderFactory propertyLoaderFactory;
@Mock
private VariableResolvingFilter variableResolvingFilter;
@Mock
private EnvironmentResolvingFilter environmentResolvingFilter;
@Mock | // Path: src/main/java/com/tngtech/propertyloader/impl/filters/EnvironmentResolvingFilter.java
// public class EnvironmentResolvingFilter extends ValueModifyingFilter {
//
// private static final Logger log = LoggerFactory.getLogger(EnvironmentResolvingFilter.class);
//
// private static final Pattern PATTERN = Pattern.compile("\\$ENV\\{(.*)\\}");
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// Matcher matcher = PATTERN.matcher(value);
// if (matcher.matches()) {
// value = getenv(matcher.group(1));
// if (value == null) {
// log.warn("There is no system property called '{}'.", matcher.group(1));
// }
// }
// return value;
// }
//
// protected String getenv(String key) {
// return System.getenv(key);
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/ThrowIfPropertyHasToBeDefined.java
// public class ThrowIfPropertyHasToBeDefined implements PropertyLoaderFilter {
//
// public static final String HAS_TO_BE_DEFINED = "<HAS_TO_BE_DEFINED>";
//
// @Override
// public void filter(Properties properties) {
// for (Map.Entry<Object, Object> entry : properties.entrySet()) {
// String key = entry.getKey().toString();
// String value = entry.getValue().toString();
// if (HAS_TO_BE_DEFINED.equals(value)) {
// StringBuilder sb = new StringBuilder();
// sb.append("\n" + "Configuration incomplete: property ").append(key).append(" is still mapped to ").append(value);
// properties.remove(entry.getKey());
// try {
// filter(properties);
// } catch (ThrowIfPropertyHasToBeDefinedException e) {
// sb.append(e.getMessage());
// }
// throw new ThrowIfPropertyHasToBeDefinedException(sb.toString());
// }
// }
// }
//
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/VariableResolvingFilter.java
// public class VariableResolvingFilter extends ValueModifyingFilter {
//
// private static final String VARIABLE_PREFIX = "${";
// private static final String VARIABLE_SUFFIX = "}";
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// if (!value.contains(VARIABLE_PREFIX)) {
// return value;
// }
//
// int startIndex = value.lastIndexOf(VARIABLE_PREFIX);
// int endIndex = value.indexOf(VARIABLE_SUFFIX, startIndex + VARIABLE_PREFIX.length());
//
// String prefix = value.substring(0, startIndex);
// String variableName = value.substring(startIndex + VARIABLE_PREFIX.length(), endIndex);
// String suffix = value.substring(endIndex + VARIABLE_SUFFIX.length());
//
// String replacement = findReplacement(variableName, properties);
// if (replacement == null) {
// throw new VariableResolvingFilterException("Error during variable resolution: No value found for variable " + variableName);
// }
// String replacedValue = prefix + replacement + suffix;
//
// // In case this is a "${deeply${nested}}${variable}", look for something to resolve again
// return filterValue(key, replacedValue, properties);
// }
//
// private String findReplacement(String variableName, Properties properties) {
// String result = properties.getProperty(variableName);
// if (result != null) {
// return result;
// }
// return System.getProperty(variableName);
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/WarnOnSurroundingWhitespace.java
// public class WarnOnSurroundingWhitespace extends ValueModifyingFilter {
//
// private static final Logger log = LoggerFactory.getLogger(WarnOnSurroundingWhitespace.class);
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// // don't show lines that end with "\n", that is ok and sometimes needed
// if (!value.trim().equals(value) && !value.endsWith("\n")) {
// log.warn("Key '{}' mapped to '{}', containing whitespace at the end. You probably do not want this.", key, value);
// }
//
// return value;
// }
// }
// Path: src/test/java/com/tngtech/propertyloader/impl/DefaultPropertyFilterContainerTest.java
import com.tngtech.propertyloader.impl.filters.EnvironmentResolvingFilter;
import com.tngtech.propertyloader.impl.filters.ThrowIfPropertyHasToBeDefined;
import com.tngtech.propertyloader.impl.filters.VariableResolvingFilter;
import com.tngtech.propertyloader.impl.filters.WarnOnSurroundingWhitespace;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.net.MalformedURLException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
package com.tngtech.propertyloader.impl;
@RunWith(MockitoJUnitRunner.class)
public class DefaultPropertyFilterContainerTest {
@InjectMocks
private DefaultPropertyFilterContainer propertyFilter;
@Mock
private PropertyLoaderFactory propertyLoaderFactory;
@Mock
private VariableResolvingFilter variableResolvingFilter;
@Mock
private EnvironmentResolvingFilter environmentResolvingFilter;
@Mock | private WarnOnSurroundingWhitespace warnOnSurroundingWhitespace; |
TNG/property-loader | src/test/java/com/tngtech/propertyloader/impl/DefaultPropertyFilterContainerTest.java | // Path: src/main/java/com/tngtech/propertyloader/impl/filters/EnvironmentResolvingFilter.java
// public class EnvironmentResolvingFilter extends ValueModifyingFilter {
//
// private static final Logger log = LoggerFactory.getLogger(EnvironmentResolvingFilter.class);
//
// private static final Pattern PATTERN = Pattern.compile("\\$ENV\\{(.*)\\}");
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// Matcher matcher = PATTERN.matcher(value);
// if (matcher.matches()) {
// value = getenv(matcher.group(1));
// if (value == null) {
// log.warn("There is no system property called '{}'.", matcher.group(1));
// }
// }
// return value;
// }
//
// protected String getenv(String key) {
// return System.getenv(key);
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/ThrowIfPropertyHasToBeDefined.java
// public class ThrowIfPropertyHasToBeDefined implements PropertyLoaderFilter {
//
// public static final String HAS_TO_BE_DEFINED = "<HAS_TO_BE_DEFINED>";
//
// @Override
// public void filter(Properties properties) {
// for (Map.Entry<Object, Object> entry : properties.entrySet()) {
// String key = entry.getKey().toString();
// String value = entry.getValue().toString();
// if (HAS_TO_BE_DEFINED.equals(value)) {
// StringBuilder sb = new StringBuilder();
// sb.append("\n" + "Configuration incomplete: property ").append(key).append(" is still mapped to ").append(value);
// properties.remove(entry.getKey());
// try {
// filter(properties);
// } catch (ThrowIfPropertyHasToBeDefinedException e) {
// sb.append(e.getMessage());
// }
// throw new ThrowIfPropertyHasToBeDefinedException(sb.toString());
// }
// }
// }
//
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/VariableResolvingFilter.java
// public class VariableResolvingFilter extends ValueModifyingFilter {
//
// private static final String VARIABLE_PREFIX = "${";
// private static final String VARIABLE_SUFFIX = "}";
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// if (!value.contains(VARIABLE_PREFIX)) {
// return value;
// }
//
// int startIndex = value.lastIndexOf(VARIABLE_PREFIX);
// int endIndex = value.indexOf(VARIABLE_SUFFIX, startIndex + VARIABLE_PREFIX.length());
//
// String prefix = value.substring(0, startIndex);
// String variableName = value.substring(startIndex + VARIABLE_PREFIX.length(), endIndex);
// String suffix = value.substring(endIndex + VARIABLE_SUFFIX.length());
//
// String replacement = findReplacement(variableName, properties);
// if (replacement == null) {
// throw new VariableResolvingFilterException("Error during variable resolution: No value found for variable " + variableName);
// }
// String replacedValue = prefix + replacement + suffix;
//
// // In case this is a "${deeply${nested}}${variable}", look for something to resolve again
// return filterValue(key, replacedValue, properties);
// }
//
// private String findReplacement(String variableName, Properties properties) {
// String result = properties.getProperty(variableName);
// if (result != null) {
// return result;
// }
// return System.getProperty(variableName);
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/WarnOnSurroundingWhitespace.java
// public class WarnOnSurroundingWhitespace extends ValueModifyingFilter {
//
// private static final Logger log = LoggerFactory.getLogger(WarnOnSurroundingWhitespace.class);
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// // don't show lines that end with "\n", that is ok and sometimes needed
// if (!value.trim().equals(value) && !value.endsWith("\n")) {
// log.warn("Key '{}' mapped to '{}', containing whitespace at the end. You probably do not want this.", key, value);
// }
//
// return value;
// }
// }
| import com.tngtech.propertyloader.impl.filters.EnvironmentResolvingFilter;
import com.tngtech.propertyloader.impl.filters.ThrowIfPropertyHasToBeDefined;
import com.tngtech.propertyloader.impl.filters.VariableResolvingFilter;
import com.tngtech.propertyloader.impl.filters.WarnOnSurroundingWhitespace;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.net.MalformedURLException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when; | package com.tngtech.propertyloader.impl;
@RunWith(MockitoJUnitRunner.class)
public class DefaultPropertyFilterContainerTest {
@InjectMocks
private DefaultPropertyFilterContainer propertyFilter;
@Mock
private PropertyLoaderFactory propertyLoaderFactory;
@Mock
private VariableResolvingFilter variableResolvingFilter;
@Mock
private EnvironmentResolvingFilter environmentResolvingFilter;
@Mock
private WarnOnSurroundingWhitespace warnOnSurroundingWhitespace;
@Mock | // Path: src/main/java/com/tngtech/propertyloader/impl/filters/EnvironmentResolvingFilter.java
// public class EnvironmentResolvingFilter extends ValueModifyingFilter {
//
// private static final Logger log = LoggerFactory.getLogger(EnvironmentResolvingFilter.class);
//
// private static final Pattern PATTERN = Pattern.compile("\\$ENV\\{(.*)\\}");
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// Matcher matcher = PATTERN.matcher(value);
// if (matcher.matches()) {
// value = getenv(matcher.group(1));
// if (value == null) {
// log.warn("There is no system property called '{}'.", matcher.group(1));
// }
// }
// return value;
// }
//
// protected String getenv(String key) {
// return System.getenv(key);
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/ThrowIfPropertyHasToBeDefined.java
// public class ThrowIfPropertyHasToBeDefined implements PropertyLoaderFilter {
//
// public static final String HAS_TO_BE_DEFINED = "<HAS_TO_BE_DEFINED>";
//
// @Override
// public void filter(Properties properties) {
// for (Map.Entry<Object, Object> entry : properties.entrySet()) {
// String key = entry.getKey().toString();
// String value = entry.getValue().toString();
// if (HAS_TO_BE_DEFINED.equals(value)) {
// StringBuilder sb = new StringBuilder();
// sb.append("\n" + "Configuration incomplete: property ").append(key).append(" is still mapped to ").append(value);
// properties.remove(entry.getKey());
// try {
// filter(properties);
// } catch (ThrowIfPropertyHasToBeDefinedException e) {
// sb.append(e.getMessage());
// }
// throw new ThrowIfPropertyHasToBeDefinedException(sb.toString());
// }
// }
// }
//
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/VariableResolvingFilter.java
// public class VariableResolvingFilter extends ValueModifyingFilter {
//
// private static final String VARIABLE_PREFIX = "${";
// private static final String VARIABLE_SUFFIX = "}";
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// if (!value.contains(VARIABLE_PREFIX)) {
// return value;
// }
//
// int startIndex = value.lastIndexOf(VARIABLE_PREFIX);
// int endIndex = value.indexOf(VARIABLE_SUFFIX, startIndex + VARIABLE_PREFIX.length());
//
// String prefix = value.substring(0, startIndex);
// String variableName = value.substring(startIndex + VARIABLE_PREFIX.length(), endIndex);
// String suffix = value.substring(endIndex + VARIABLE_SUFFIX.length());
//
// String replacement = findReplacement(variableName, properties);
// if (replacement == null) {
// throw new VariableResolvingFilterException("Error during variable resolution: No value found for variable " + variableName);
// }
// String replacedValue = prefix + replacement + suffix;
//
// // In case this is a "${deeply${nested}}${variable}", look for something to resolve again
// return filterValue(key, replacedValue, properties);
// }
//
// private String findReplacement(String variableName, Properties properties) {
// String result = properties.getProperty(variableName);
// if (result != null) {
// return result;
// }
// return System.getProperty(variableName);
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/WarnOnSurroundingWhitespace.java
// public class WarnOnSurroundingWhitespace extends ValueModifyingFilter {
//
// private static final Logger log = LoggerFactory.getLogger(WarnOnSurroundingWhitespace.class);
//
// @Override
// protected String filterValue(String key, String value, Properties properties) {
// // don't show lines that end with "\n", that is ok and sometimes needed
// if (!value.trim().equals(value) && !value.endsWith("\n")) {
// log.warn("Key '{}' mapped to '{}', containing whitespace at the end. You probably do not want this.", key, value);
// }
//
// return value;
// }
// }
// Path: src/test/java/com/tngtech/propertyloader/impl/DefaultPropertyFilterContainerTest.java
import com.tngtech.propertyloader.impl.filters.EnvironmentResolvingFilter;
import com.tngtech.propertyloader.impl.filters.ThrowIfPropertyHasToBeDefined;
import com.tngtech.propertyloader.impl.filters.VariableResolvingFilter;
import com.tngtech.propertyloader.impl.filters.WarnOnSurroundingWhitespace;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.net.MalformedURLException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
package com.tngtech.propertyloader.impl;
@RunWith(MockitoJUnitRunner.class)
public class DefaultPropertyFilterContainerTest {
@InjectMocks
private DefaultPropertyFilterContainer propertyFilter;
@Mock
private PropertyLoaderFactory propertyLoaderFactory;
@Mock
private VariableResolvingFilter variableResolvingFilter;
@Mock
private EnvironmentResolvingFilter environmentResolvingFilter;
@Mock
private WarnOnSurroundingWhitespace warnOnSurroundingWhitespace;
@Mock | private ThrowIfPropertyHasToBeDefined throwIfPropertyHasToBeDefined; |
TNG/property-loader | src/main/java/com/tngtech/propertyloader/impl/PropertyFileReader.java | // Path: src/main/java/com/tngtech/propertyloader/impl/interfaces/PropertyLoaderOpener.java
// public interface PropertyLoaderOpener {
//
// /**
// * Attempt to find and open some property file.
// *
// * @param fileName A relative filename (using '/' as directory separator on all platforms)
// * @return An input stream reading from that file, or null if the file could not be found
// */
// InputStream open(String fileName);
// }
| import com.tngtech.propertyloader.impl.interfaces.PropertyLoaderOpener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties; | package com.tngtech.propertyloader.impl;
public class PropertyFileReader {
private static final Logger log = LoggerFactory.getLogger(PropertyFileReader.class);
private final PropertyLoaderFactory propertyLoaderFactory;
public PropertyFileReader(PropertyLoaderFactory propertyLoaderFactory) {
this.propertyLoaderFactory = propertyLoaderFactory;
}
| // Path: src/main/java/com/tngtech/propertyloader/impl/interfaces/PropertyLoaderOpener.java
// public interface PropertyLoaderOpener {
//
// /**
// * Attempt to find and open some property file.
// *
// * @param fileName A relative filename (using '/' as directory separator on all platforms)
// * @return An input stream reading from that file, or null if the file could not be found
// */
// InputStream open(String fileName);
// }
// Path: src/main/java/com/tngtech/propertyloader/impl/PropertyFileReader.java
import com.tngtech.propertyloader.impl.interfaces.PropertyLoaderOpener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;
package com.tngtech.propertyloader.impl;
public class PropertyFileReader {
private static final Logger log = LoggerFactory.getLogger(PropertyFileReader.class);
private final PropertyLoaderFactory propertyLoaderFactory;
public PropertyFileReader(PropertyLoaderFactory propertyLoaderFactory) {
this.propertyLoaderFactory = propertyLoaderFactory;
}
| public Properties tryToReadPropertiesFromFile(String fileName, String propertyFileEncoding, PropertyLoaderOpener opener) { |
TNG/property-loader | src/main/java/com/tngtech/propertyloader/impl/DefaultPropertyLocationContainer.java | // Path: src/main/java/com/tngtech/propertyloader/impl/interfaces/PropertyLoaderOpener.java
// public interface PropertyLoaderOpener {
//
// /**
// * Attempt to find and open some property file.
// *
// * @param fileName A relative filename (using '/' as directory separator on all platforms)
// * @return An input stream reading from that file, or null if the file could not be found
// */
// InputStream open(String fileName);
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/interfaces/PropertyLocationsContainer.java
// public interface PropertyLocationsContainer<T> {
//
// T atDefaultLocations();
//
// T atCurrentDirectory();
//
// T atHomeDirectory();
//
// T atDirectory(String directory);
//
// T atContextClassPath();
//
// T atRelativeToClass(Class<?> reference);
//
// T atClassLoader(ClassLoader classLoader);
//
// T atBaseURL(URL url);
// }
| import com.tngtech.propertyloader.impl.interfaces.PropertyLoaderOpener;
import com.tngtech.propertyloader.impl.interfaces.PropertyLocationsContainer;
import java.net.URL;
import java.util.ArrayList;
import java.util.List; | package com.tngtech.propertyloader.impl;
public class DefaultPropertyLocationContainer implements PropertyLocationsContainer<DefaultPropertyLocationContainer> {
private final PropertyLoaderFactory propertyLoaderFactory;
| // Path: src/main/java/com/tngtech/propertyloader/impl/interfaces/PropertyLoaderOpener.java
// public interface PropertyLoaderOpener {
//
// /**
// * Attempt to find and open some property file.
// *
// * @param fileName A relative filename (using '/' as directory separator on all platforms)
// * @return An input stream reading from that file, or null if the file could not be found
// */
// InputStream open(String fileName);
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/interfaces/PropertyLocationsContainer.java
// public interface PropertyLocationsContainer<T> {
//
// T atDefaultLocations();
//
// T atCurrentDirectory();
//
// T atHomeDirectory();
//
// T atDirectory(String directory);
//
// T atContextClassPath();
//
// T atRelativeToClass(Class<?> reference);
//
// T atClassLoader(ClassLoader classLoader);
//
// T atBaseURL(URL url);
// }
// Path: src/main/java/com/tngtech/propertyloader/impl/DefaultPropertyLocationContainer.java
import com.tngtech.propertyloader.impl.interfaces.PropertyLoaderOpener;
import com.tngtech.propertyloader.impl.interfaces.PropertyLocationsContainer;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
package com.tngtech.propertyloader.impl;
public class DefaultPropertyLocationContainer implements PropertyLocationsContainer<DefaultPropertyLocationContainer> {
private final PropertyLoaderFactory propertyLoaderFactory;
| private final List<PropertyLoaderOpener> openers = new ArrayList<>(); |
TNG/property-loader | src/test/java/com/tngtech/propertyloader/impl/DefaultPropertyLocationContainerTest.java | // Path: src/main/java/com/tngtech/propertyloader/impl/openers/ClassLoaderOpener.java
// public class ClassLoaderOpener implements PropertyLoaderOpener {
//
// private final ClassLoader classLoader;
//
// public ClassLoaderOpener(ClassLoader classLoader) {
// this.classLoader = classLoader;
// }
//
// public InputStream open(String fileName) {
// return classLoader.getResourceAsStream(fileName);
// }
//
// @Override
// public String toString() {
// return "by classloader " + classLoader;
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/ContextClassLoaderOpener.java
// public class ContextClassLoaderOpener implements PropertyLoaderOpener {
//
// public InputStream open(String fileName) {
// ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
// return contextClassLoader.getResourceAsStream(fileName);
// }
//
// @Override
// public String toString() {
// return "in classpath";
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/RelativeToClassOpener.java
// public class RelativeToClassOpener implements PropertyLoaderOpener {
//
// private final Class<?> reference;
//
// public RelativeToClassOpener(Class<?> reference) {
// this.reference = reference;
// }
//
// public InputStream open(String filename) {
// return reference.getResourceAsStream(filename);
// }
//
// @Override
// public String toString() {
// return "near " + reference;
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/URLFileOpener.java
// public class URLFileOpener implements PropertyLoaderOpener {
//
// private URL url;
//
// public URLFileOpener() {
// try {
// this.url = new File("").toURI().toURL();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("THIS CAN NOT HAPPEN: error while forming URL from path '%s'", ""), e);
// }
// }
//
// public URLFileOpener(URL url) {
// this.url = url;
// }
//
// public URLFileOpener(String address) {
// try {
// this.url = new File(address.replace("/", File.separator)).toURI().toURL();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("THIS SHOULD NOT HAPPEN: error while forming URL from path '%s'", address), e);
// }
// }
//
// /**
// * Tries to open the given file.
// * A filename that starts with '/' is understood as an absolute path,
// * i.e. the URLFileOpener forgets about its path.
// *
// * @param fileName the filename
// * @return InputStream of the resource found at the given URL
// */
// public InputStream open(String fileName) {
// try {
// URL urlToFile = new URL(url, fileName);
// return urlToFile.openStream();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("error while forming new URL from URL %s and filename %s", url.getPath(), fileName), e);
// } catch (IOException e) {
// return null;
// }
// }
//
// @Override
// public String toString() {
// return "in path " + url.getPath();
// }
// }
| import com.tngtech.propertyloader.impl.openers.ClassLoaderOpener;
import com.tngtech.propertyloader.impl.openers.ContextClassLoaderOpener;
import com.tngtech.propertyloader.impl.openers.RelativeToClassOpener;
import com.tngtech.propertyloader.impl.openers.URLFileOpener;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when; | package com.tngtech.propertyloader.impl;
@RunWith(MockitoJUnitRunner.class)
public class DefaultPropertyLocationContainerTest {
@InjectMocks
private DefaultPropertyLocationContainer propertyLocation;
@Mock
private PropertyLoaderFactory propertyLoaderFactory;
@Mock | // Path: src/main/java/com/tngtech/propertyloader/impl/openers/ClassLoaderOpener.java
// public class ClassLoaderOpener implements PropertyLoaderOpener {
//
// private final ClassLoader classLoader;
//
// public ClassLoaderOpener(ClassLoader classLoader) {
// this.classLoader = classLoader;
// }
//
// public InputStream open(String fileName) {
// return classLoader.getResourceAsStream(fileName);
// }
//
// @Override
// public String toString() {
// return "by classloader " + classLoader;
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/ContextClassLoaderOpener.java
// public class ContextClassLoaderOpener implements PropertyLoaderOpener {
//
// public InputStream open(String fileName) {
// ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
// return contextClassLoader.getResourceAsStream(fileName);
// }
//
// @Override
// public String toString() {
// return "in classpath";
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/RelativeToClassOpener.java
// public class RelativeToClassOpener implements PropertyLoaderOpener {
//
// private final Class<?> reference;
//
// public RelativeToClassOpener(Class<?> reference) {
// this.reference = reference;
// }
//
// public InputStream open(String filename) {
// return reference.getResourceAsStream(filename);
// }
//
// @Override
// public String toString() {
// return "near " + reference;
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/URLFileOpener.java
// public class URLFileOpener implements PropertyLoaderOpener {
//
// private URL url;
//
// public URLFileOpener() {
// try {
// this.url = new File("").toURI().toURL();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("THIS CAN NOT HAPPEN: error while forming URL from path '%s'", ""), e);
// }
// }
//
// public URLFileOpener(URL url) {
// this.url = url;
// }
//
// public URLFileOpener(String address) {
// try {
// this.url = new File(address.replace("/", File.separator)).toURI().toURL();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("THIS SHOULD NOT HAPPEN: error while forming URL from path '%s'", address), e);
// }
// }
//
// /**
// * Tries to open the given file.
// * A filename that starts with '/' is understood as an absolute path,
// * i.e. the URLFileOpener forgets about its path.
// *
// * @param fileName the filename
// * @return InputStream of the resource found at the given URL
// */
// public InputStream open(String fileName) {
// try {
// URL urlToFile = new URL(url, fileName);
// return urlToFile.openStream();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("error while forming new URL from URL %s and filename %s", url.getPath(), fileName), e);
// } catch (IOException e) {
// return null;
// }
// }
//
// @Override
// public String toString() {
// return "in path " + url.getPath();
// }
// }
// Path: src/test/java/com/tngtech/propertyloader/impl/DefaultPropertyLocationContainerTest.java
import com.tngtech.propertyloader.impl.openers.ClassLoaderOpener;
import com.tngtech.propertyloader.impl.openers.ContextClassLoaderOpener;
import com.tngtech.propertyloader.impl.openers.RelativeToClassOpener;
import com.tngtech.propertyloader.impl.openers.URLFileOpener;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
package com.tngtech.propertyloader.impl;
@RunWith(MockitoJUnitRunner.class)
public class DefaultPropertyLocationContainerTest {
@InjectMocks
private DefaultPropertyLocationContainer propertyLocation;
@Mock
private PropertyLoaderFactory propertyLoaderFactory;
@Mock | private URLFileOpener urlFileOpener; |
TNG/property-loader | src/test/java/com/tngtech/propertyloader/impl/DefaultPropertyLocationContainerTest.java | // Path: src/main/java/com/tngtech/propertyloader/impl/openers/ClassLoaderOpener.java
// public class ClassLoaderOpener implements PropertyLoaderOpener {
//
// private final ClassLoader classLoader;
//
// public ClassLoaderOpener(ClassLoader classLoader) {
// this.classLoader = classLoader;
// }
//
// public InputStream open(String fileName) {
// return classLoader.getResourceAsStream(fileName);
// }
//
// @Override
// public String toString() {
// return "by classloader " + classLoader;
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/ContextClassLoaderOpener.java
// public class ContextClassLoaderOpener implements PropertyLoaderOpener {
//
// public InputStream open(String fileName) {
// ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
// return contextClassLoader.getResourceAsStream(fileName);
// }
//
// @Override
// public String toString() {
// return "in classpath";
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/RelativeToClassOpener.java
// public class RelativeToClassOpener implements PropertyLoaderOpener {
//
// private final Class<?> reference;
//
// public RelativeToClassOpener(Class<?> reference) {
// this.reference = reference;
// }
//
// public InputStream open(String filename) {
// return reference.getResourceAsStream(filename);
// }
//
// @Override
// public String toString() {
// return "near " + reference;
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/URLFileOpener.java
// public class URLFileOpener implements PropertyLoaderOpener {
//
// private URL url;
//
// public URLFileOpener() {
// try {
// this.url = new File("").toURI().toURL();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("THIS CAN NOT HAPPEN: error while forming URL from path '%s'", ""), e);
// }
// }
//
// public URLFileOpener(URL url) {
// this.url = url;
// }
//
// public URLFileOpener(String address) {
// try {
// this.url = new File(address.replace("/", File.separator)).toURI().toURL();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("THIS SHOULD NOT HAPPEN: error while forming URL from path '%s'", address), e);
// }
// }
//
// /**
// * Tries to open the given file.
// * A filename that starts with '/' is understood as an absolute path,
// * i.e. the URLFileOpener forgets about its path.
// *
// * @param fileName the filename
// * @return InputStream of the resource found at the given URL
// */
// public InputStream open(String fileName) {
// try {
// URL urlToFile = new URL(url, fileName);
// return urlToFile.openStream();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("error while forming new URL from URL %s and filename %s", url.getPath(), fileName), e);
// } catch (IOException e) {
// return null;
// }
// }
//
// @Override
// public String toString() {
// return "in path " + url.getPath();
// }
// }
| import com.tngtech.propertyloader.impl.openers.ClassLoaderOpener;
import com.tngtech.propertyloader.impl.openers.ContextClassLoaderOpener;
import com.tngtech.propertyloader.impl.openers.RelativeToClassOpener;
import com.tngtech.propertyloader.impl.openers.URLFileOpener;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when; | package com.tngtech.propertyloader.impl;
@RunWith(MockitoJUnitRunner.class)
public class DefaultPropertyLocationContainerTest {
@InjectMocks
private DefaultPropertyLocationContainer propertyLocation;
@Mock
private PropertyLoaderFactory propertyLoaderFactory;
@Mock
private URLFileOpener urlFileOpener;
@Mock | // Path: src/main/java/com/tngtech/propertyloader/impl/openers/ClassLoaderOpener.java
// public class ClassLoaderOpener implements PropertyLoaderOpener {
//
// private final ClassLoader classLoader;
//
// public ClassLoaderOpener(ClassLoader classLoader) {
// this.classLoader = classLoader;
// }
//
// public InputStream open(String fileName) {
// return classLoader.getResourceAsStream(fileName);
// }
//
// @Override
// public String toString() {
// return "by classloader " + classLoader;
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/ContextClassLoaderOpener.java
// public class ContextClassLoaderOpener implements PropertyLoaderOpener {
//
// public InputStream open(String fileName) {
// ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
// return contextClassLoader.getResourceAsStream(fileName);
// }
//
// @Override
// public String toString() {
// return "in classpath";
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/RelativeToClassOpener.java
// public class RelativeToClassOpener implements PropertyLoaderOpener {
//
// private final Class<?> reference;
//
// public RelativeToClassOpener(Class<?> reference) {
// this.reference = reference;
// }
//
// public InputStream open(String filename) {
// return reference.getResourceAsStream(filename);
// }
//
// @Override
// public String toString() {
// return "near " + reference;
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/URLFileOpener.java
// public class URLFileOpener implements PropertyLoaderOpener {
//
// private URL url;
//
// public URLFileOpener() {
// try {
// this.url = new File("").toURI().toURL();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("THIS CAN NOT HAPPEN: error while forming URL from path '%s'", ""), e);
// }
// }
//
// public URLFileOpener(URL url) {
// this.url = url;
// }
//
// public URLFileOpener(String address) {
// try {
// this.url = new File(address.replace("/", File.separator)).toURI().toURL();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("THIS SHOULD NOT HAPPEN: error while forming URL from path '%s'", address), e);
// }
// }
//
// /**
// * Tries to open the given file.
// * A filename that starts with '/' is understood as an absolute path,
// * i.e. the URLFileOpener forgets about its path.
// *
// * @param fileName the filename
// * @return InputStream of the resource found at the given URL
// */
// public InputStream open(String fileName) {
// try {
// URL urlToFile = new URL(url, fileName);
// return urlToFile.openStream();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("error while forming new URL from URL %s and filename %s", url.getPath(), fileName), e);
// } catch (IOException e) {
// return null;
// }
// }
//
// @Override
// public String toString() {
// return "in path " + url.getPath();
// }
// }
// Path: src/test/java/com/tngtech/propertyloader/impl/DefaultPropertyLocationContainerTest.java
import com.tngtech.propertyloader.impl.openers.ClassLoaderOpener;
import com.tngtech.propertyloader.impl.openers.ContextClassLoaderOpener;
import com.tngtech.propertyloader.impl.openers.RelativeToClassOpener;
import com.tngtech.propertyloader.impl.openers.URLFileOpener;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
package com.tngtech.propertyloader.impl;
@RunWith(MockitoJUnitRunner.class)
public class DefaultPropertyLocationContainerTest {
@InjectMocks
private DefaultPropertyLocationContainer propertyLocation;
@Mock
private PropertyLoaderFactory propertyLoaderFactory;
@Mock
private URLFileOpener urlFileOpener;
@Mock | private ContextClassLoaderOpener contextClassLoader; |
TNG/property-loader | src/test/java/com/tngtech/propertyloader/impl/DefaultPropertyLocationContainerTest.java | // Path: src/main/java/com/tngtech/propertyloader/impl/openers/ClassLoaderOpener.java
// public class ClassLoaderOpener implements PropertyLoaderOpener {
//
// private final ClassLoader classLoader;
//
// public ClassLoaderOpener(ClassLoader classLoader) {
// this.classLoader = classLoader;
// }
//
// public InputStream open(String fileName) {
// return classLoader.getResourceAsStream(fileName);
// }
//
// @Override
// public String toString() {
// return "by classloader " + classLoader;
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/ContextClassLoaderOpener.java
// public class ContextClassLoaderOpener implements PropertyLoaderOpener {
//
// public InputStream open(String fileName) {
// ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
// return contextClassLoader.getResourceAsStream(fileName);
// }
//
// @Override
// public String toString() {
// return "in classpath";
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/RelativeToClassOpener.java
// public class RelativeToClassOpener implements PropertyLoaderOpener {
//
// private final Class<?> reference;
//
// public RelativeToClassOpener(Class<?> reference) {
// this.reference = reference;
// }
//
// public InputStream open(String filename) {
// return reference.getResourceAsStream(filename);
// }
//
// @Override
// public String toString() {
// return "near " + reference;
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/URLFileOpener.java
// public class URLFileOpener implements PropertyLoaderOpener {
//
// private URL url;
//
// public URLFileOpener() {
// try {
// this.url = new File("").toURI().toURL();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("THIS CAN NOT HAPPEN: error while forming URL from path '%s'", ""), e);
// }
// }
//
// public URLFileOpener(URL url) {
// this.url = url;
// }
//
// public URLFileOpener(String address) {
// try {
// this.url = new File(address.replace("/", File.separator)).toURI().toURL();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("THIS SHOULD NOT HAPPEN: error while forming URL from path '%s'", address), e);
// }
// }
//
// /**
// * Tries to open the given file.
// * A filename that starts with '/' is understood as an absolute path,
// * i.e. the URLFileOpener forgets about its path.
// *
// * @param fileName the filename
// * @return InputStream of the resource found at the given URL
// */
// public InputStream open(String fileName) {
// try {
// URL urlToFile = new URL(url, fileName);
// return urlToFile.openStream();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("error while forming new URL from URL %s and filename %s", url.getPath(), fileName), e);
// } catch (IOException e) {
// return null;
// }
// }
//
// @Override
// public String toString() {
// return "in path " + url.getPath();
// }
// }
| import com.tngtech.propertyloader.impl.openers.ClassLoaderOpener;
import com.tngtech.propertyloader.impl.openers.ContextClassLoaderOpener;
import com.tngtech.propertyloader.impl.openers.RelativeToClassOpener;
import com.tngtech.propertyloader.impl.openers.URLFileOpener;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when; | package com.tngtech.propertyloader.impl;
@RunWith(MockitoJUnitRunner.class)
public class DefaultPropertyLocationContainerTest {
@InjectMocks
private DefaultPropertyLocationContainer propertyLocation;
@Mock
private PropertyLoaderFactory propertyLoaderFactory;
@Mock
private URLFileOpener urlFileOpener;
@Mock
private ContextClassLoaderOpener contextClassLoader;
@Mock | // Path: src/main/java/com/tngtech/propertyloader/impl/openers/ClassLoaderOpener.java
// public class ClassLoaderOpener implements PropertyLoaderOpener {
//
// private final ClassLoader classLoader;
//
// public ClassLoaderOpener(ClassLoader classLoader) {
// this.classLoader = classLoader;
// }
//
// public InputStream open(String fileName) {
// return classLoader.getResourceAsStream(fileName);
// }
//
// @Override
// public String toString() {
// return "by classloader " + classLoader;
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/ContextClassLoaderOpener.java
// public class ContextClassLoaderOpener implements PropertyLoaderOpener {
//
// public InputStream open(String fileName) {
// ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
// return contextClassLoader.getResourceAsStream(fileName);
// }
//
// @Override
// public String toString() {
// return "in classpath";
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/RelativeToClassOpener.java
// public class RelativeToClassOpener implements PropertyLoaderOpener {
//
// private final Class<?> reference;
//
// public RelativeToClassOpener(Class<?> reference) {
// this.reference = reference;
// }
//
// public InputStream open(String filename) {
// return reference.getResourceAsStream(filename);
// }
//
// @Override
// public String toString() {
// return "near " + reference;
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/URLFileOpener.java
// public class URLFileOpener implements PropertyLoaderOpener {
//
// private URL url;
//
// public URLFileOpener() {
// try {
// this.url = new File("").toURI().toURL();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("THIS CAN NOT HAPPEN: error while forming URL from path '%s'", ""), e);
// }
// }
//
// public URLFileOpener(URL url) {
// this.url = url;
// }
//
// public URLFileOpener(String address) {
// try {
// this.url = new File(address.replace("/", File.separator)).toURI().toURL();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("THIS SHOULD NOT HAPPEN: error while forming URL from path '%s'", address), e);
// }
// }
//
// /**
// * Tries to open the given file.
// * A filename that starts with '/' is understood as an absolute path,
// * i.e. the URLFileOpener forgets about its path.
// *
// * @param fileName the filename
// * @return InputStream of the resource found at the given URL
// */
// public InputStream open(String fileName) {
// try {
// URL urlToFile = new URL(url, fileName);
// return urlToFile.openStream();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("error while forming new URL from URL %s and filename %s", url.getPath(), fileName), e);
// } catch (IOException e) {
// return null;
// }
// }
//
// @Override
// public String toString() {
// return "in path " + url.getPath();
// }
// }
// Path: src/test/java/com/tngtech/propertyloader/impl/DefaultPropertyLocationContainerTest.java
import com.tngtech.propertyloader.impl.openers.ClassLoaderOpener;
import com.tngtech.propertyloader.impl.openers.ContextClassLoaderOpener;
import com.tngtech.propertyloader.impl.openers.RelativeToClassOpener;
import com.tngtech.propertyloader.impl.openers.URLFileOpener;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
package com.tngtech.propertyloader.impl;
@RunWith(MockitoJUnitRunner.class)
public class DefaultPropertyLocationContainerTest {
@InjectMocks
private DefaultPropertyLocationContainer propertyLocation;
@Mock
private PropertyLoaderFactory propertyLoaderFactory;
@Mock
private URLFileOpener urlFileOpener;
@Mock
private ContextClassLoaderOpener contextClassLoader;
@Mock | private RelativeToClassOpener relativeToClassOpener; |
TNG/property-loader | src/test/java/com/tngtech/propertyloader/impl/DefaultPropertyLocationContainerTest.java | // Path: src/main/java/com/tngtech/propertyloader/impl/openers/ClassLoaderOpener.java
// public class ClassLoaderOpener implements PropertyLoaderOpener {
//
// private final ClassLoader classLoader;
//
// public ClassLoaderOpener(ClassLoader classLoader) {
// this.classLoader = classLoader;
// }
//
// public InputStream open(String fileName) {
// return classLoader.getResourceAsStream(fileName);
// }
//
// @Override
// public String toString() {
// return "by classloader " + classLoader;
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/ContextClassLoaderOpener.java
// public class ContextClassLoaderOpener implements PropertyLoaderOpener {
//
// public InputStream open(String fileName) {
// ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
// return contextClassLoader.getResourceAsStream(fileName);
// }
//
// @Override
// public String toString() {
// return "in classpath";
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/RelativeToClassOpener.java
// public class RelativeToClassOpener implements PropertyLoaderOpener {
//
// private final Class<?> reference;
//
// public RelativeToClassOpener(Class<?> reference) {
// this.reference = reference;
// }
//
// public InputStream open(String filename) {
// return reference.getResourceAsStream(filename);
// }
//
// @Override
// public String toString() {
// return "near " + reference;
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/URLFileOpener.java
// public class URLFileOpener implements PropertyLoaderOpener {
//
// private URL url;
//
// public URLFileOpener() {
// try {
// this.url = new File("").toURI().toURL();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("THIS CAN NOT HAPPEN: error while forming URL from path '%s'", ""), e);
// }
// }
//
// public URLFileOpener(URL url) {
// this.url = url;
// }
//
// public URLFileOpener(String address) {
// try {
// this.url = new File(address.replace("/", File.separator)).toURI().toURL();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("THIS SHOULD NOT HAPPEN: error while forming URL from path '%s'", address), e);
// }
// }
//
// /**
// * Tries to open the given file.
// * A filename that starts with '/' is understood as an absolute path,
// * i.e. the URLFileOpener forgets about its path.
// *
// * @param fileName the filename
// * @return InputStream of the resource found at the given URL
// */
// public InputStream open(String fileName) {
// try {
// URL urlToFile = new URL(url, fileName);
// return urlToFile.openStream();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("error while forming new URL from URL %s and filename %s", url.getPath(), fileName), e);
// } catch (IOException e) {
// return null;
// }
// }
//
// @Override
// public String toString() {
// return "in path " + url.getPath();
// }
// }
| import com.tngtech.propertyloader.impl.openers.ClassLoaderOpener;
import com.tngtech.propertyloader.impl.openers.ContextClassLoaderOpener;
import com.tngtech.propertyloader.impl.openers.RelativeToClassOpener;
import com.tngtech.propertyloader.impl.openers.URLFileOpener;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when; | package com.tngtech.propertyloader.impl;
@RunWith(MockitoJUnitRunner.class)
public class DefaultPropertyLocationContainerTest {
@InjectMocks
private DefaultPropertyLocationContainer propertyLocation;
@Mock
private PropertyLoaderFactory propertyLoaderFactory;
@Mock
private URLFileOpener urlFileOpener;
@Mock
private ContextClassLoaderOpener contextClassLoader;
@Mock
private RelativeToClassOpener relativeToClassOpener;
@Mock | // Path: src/main/java/com/tngtech/propertyloader/impl/openers/ClassLoaderOpener.java
// public class ClassLoaderOpener implements PropertyLoaderOpener {
//
// private final ClassLoader classLoader;
//
// public ClassLoaderOpener(ClassLoader classLoader) {
// this.classLoader = classLoader;
// }
//
// public InputStream open(String fileName) {
// return classLoader.getResourceAsStream(fileName);
// }
//
// @Override
// public String toString() {
// return "by classloader " + classLoader;
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/ContextClassLoaderOpener.java
// public class ContextClassLoaderOpener implements PropertyLoaderOpener {
//
// public InputStream open(String fileName) {
// ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
// return contextClassLoader.getResourceAsStream(fileName);
// }
//
// @Override
// public String toString() {
// return "in classpath";
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/RelativeToClassOpener.java
// public class RelativeToClassOpener implements PropertyLoaderOpener {
//
// private final Class<?> reference;
//
// public RelativeToClassOpener(Class<?> reference) {
// this.reference = reference;
// }
//
// public InputStream open(String filename) {
// return reference.getResourceAsStream(filename);
// }
//
// @Override
// public String toString() {
// return "near " + reference;
// }
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/openers/URLFileOpener.java
// public class URLFileOpener implements PropertyLoaderOpener {
//
// private URL url;
//
// public URLFileOpener() {
// try {
// this.url = new File("").toURI().toURL();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("THIS CAN NOT HAPPEN: error while forming URL from path '%s'", ""), e);
// }
// }
//
// public URLFileOpener(URL url) {
// this.url = url;
// }
//
// public URLFileOpener(String address) {
// try {
// this.url = new File(address.replace("/", File.separator)).toURI().toURL();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("THIS SHOULD NOT HAPPEN: error while forming URL from path '%s'", address), e);
// }
// }
//
// /**
// * Tries to open the given file.
// * A filename that starts with '/' is understood as an absolute path,
// * i.e. the URLFileOpener forgets about its path.
// *
// * @param fileName the filename
// * @return InputStream of the resource found at the given URL
// */
// public InputStream open(String fileName) {
// try {
// URL urlToFile = new URL(url, fileName);
// return urlToFile.openStream();
// } catch (MalformedURLException e) {
// throw new RuntimeException(String.format("error while forming new URL from URL %s and filename %s", url.getPath(), fileName), e);
// } catch (IOException e) {
// return null;
// }
// }
//
// @Override
// public String toString() {
// return "in path " + url.getPath();
// }
// }
// Path: src/test/java/com/tngtech/propertyloader/impl/DefaultPropertyLocationContainerTest.java
import com.tngtech.propertyloader.impl.openers.ClassLoaderOpener;
import com.tngtech.propertyloader.impl.openers.ContextClassLoaderOpener;
import com.tngtech.propertyloader.impl.openers.RelativeToClassOpener;
import com.tngtech.propertyloader.impl.openers.URLFileOpener;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
package com.tngtech.propertyloader.impl;
@RunWith(MockitoJUnitRunner.class)
public class DefaultPropertyLocationContainerTest {
@InjectMocks
private DefaultPropertyLocationContainer propertyLocation;
@Mock
private PropertyLoaderFactory propertyLoaderFactory;
@Mock
private URLFileOpener urlFileOpener;
@Mock
private ContextClassLoaderOpener contextClassLoader;
@Mock
private RelativeToClassOpener relativeToClassOpener;
@Mock | private ClassLoaderOpener classLoaderOpener; |
TNG/property-loader | src/main/java/com/tngtech/propertyloader/impl/filters/DecryptingFilter.java | // Path: src/main/java/com/tngtech/propertyloader/Obfuscator.java
// public class Obfuscator {
//
// private static final String ENCRYPTION_ALGORITHM = "Blowfish";
// private static final String ENCRYPTION_ALGORITHM_MODIFIER = "/ECB/PKCS5Padding";
// private static final String ENCODING = "UTF-8";
//
// private final Base64.Encoder base64Encoder = Base64.getEncoder();
// private final Base64.Decoder base64Decoder = Base64.getDecoder();
// private final SecretKeySpec dataEncryptionSecretKeySpec;
//
// public Obfuscator(String password) {
// byte[] salt = {65, 110, 100, 114, 111, 105, 100, 75, 105, 116, 75, 97, 116, 13, 1, 20, 20, 9, 1, 19};
// SecretKeyFactory factory;
// try {
// factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
// SecretKey tmp = factory.generateSecret(new PBEKeySpec(password.toCharArray(), salt, 100, 128));
// dataEncryptionSecretKeySpec = new SecretKeySpec(tmp.getEncoded(), ENCRYPTION_ALGORITHM);
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// }
//
// /**
// * Encrypt and base64-encode a String.
// *
// * @param toEncrypt - the String to encrypt.
// * @return the Blowfish-encrypted and base64-encoded String.
// */
// public String encrypt(String toEncrypt) {
// byte[] encryptedBytes = encryptInternal(dataEncryptionSecretKeySpec, toEncrypt);
// return new String(base64Encoder.encode(encryptedBytes));
// }
//
// /**
// * Internal Encryption method.
// *
// * @param key - the SecretKeySpec used to encrypt
// * @param toEncrypt - the String to encrypt
// * @return the encrypted String (as byte[])
// */
// private byte[] encryptInternal(SecretKeySpec key, String toEncrypt) {
// try {
// Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM + ENCRYPTION_ALGORITHM_MODIFIER);
// cipher.init(Cipher.ENCRYPT_MODE, key);
// return cipher.doFinal(toEncrypt.getBytes(ENCODING));
// } catch (GeneralSecurityException e) {
// throw new RuntimeException("Exception during decryptInternal: " + e, e);
// } catch (UnsupportedEncodingException e) {
// throw new RuntimeException("Exception during encryptInternal: " + e, e);
// }
// }
//
// /**
// * Decrypt an encrypted and base64-encoded String
// *
// * @param toDecrypt - the encrypted and base64-encoded String
// * @return the plaintext String
// */
// public String decrypt(String toDecrypt) {
// byte[] encryptedBytes = base64Decoder.decode(toDecrypt);
// return decryptInternal(dataEncryptionSecretKeySpec, encryptedBytes);
// }
//
// /**
// * Internal decryption method.
// *
// * @param key - the SecretKeySpec used to decrypt
// * @param encryptedBytes - the byte[] to decrypt
// * @return the decrypted plaintext String.
// */
// private String decryptInternal(SecretKeySpec key, byte[] encryptedBytes) {
// try {
// Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM + ENCRYPTION_ALGORITHM_MODIFIER);
// cipher.init(Cipher.DECRYPT_MODE, key);
// byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
// return new String(decryptedBytes, ENCODING);
// } catch (GeneralSecurityException e) {
// throw new RuntimeException("Exception during decryptInternal: " + e, e);
// } catch (UnsupportedEncodingException e) {
// throw new RuntimeException("Exception during encryptInternal: " + e, e);
// }
// }
// }
| import com.tngtech.propertyloader.Obfuscator;
import java.util.Properties; | package com.tngtech.propertyloader.impl.filters;
/**
* Decrypts property values that are prefixed with 'DECRYPT:'.
* The password must be provided in the properties, with key 'decryptingFilterPassword'
*/
public class DecryptingFilter extends ValueModifyingFilter {
public static final String DECRYPT_PREFIX = "DECRYPT:";
@Override
protected String filterValue(String key, String value, Properties properties) {
if (!value.startsWith(DECRYPT_PREFIX)) {
return value;
}
String encryptedValue = value.substring(DECRYPT_PREFIX.length());
String password = properties.getProperty("decryptingFilterPassword");
if (password == null) {
throw new DecryptingFilterException("Decryption failed: Password not found in properties");
}
| // Path: src/main/java/com/tngtech/propertyloader/Obfuscator.java
// public class Obfuscator {
//
// private static final String ENCRYPTION_ALGORITHM = "Blowfish";
// private static final String ENCRYPTION_ALGORITHM_MODIFIER = "/ECB/PKCS5Padding";
// private static final String ENCODING = "UTF-8";
//
// private final Base64.Encoder base64Encoder = Base64.getEncoder();
// private final Base64.Decoder base64Decoder = Base64.getDecoder();
// private final SecretKeySpec dataEncryptionSecretKeySpec;
//
// public Obfuscator(String password) {
// byte[] salt = {65, 110, 100, 114, 111, 105, 100, 75, 105, 116, 75, 97, 116, 13, 1, 20, 20, 9, 1, 19};
// SecretKeyFactory factory;
// try {
// factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
// SecretKey tmp = factory.generateSecret(new PBEKeySpec(password.toCharArray(), salt, 100, 128));
// dataEncryptionSecretKeySpec = new SecretKeySpec(tmp.getEncoded(), ENCRYPTION_ALGORITHM);
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// }
//
// /**
// * Encrypt and base64-encode a String.
// *
// * @param toEncrypt - the String to encrypt.
// * @return the Blowfish-encrypted and base64-encoded String.
// */
// public String encrypt(String toEncrypt) {
// byte[] encryptedBytes = encryptInternal(dataEncryptionSecretKeySpec, toEncrypt);
// return new String(base64Encoder.encode(encryptedBytes));
// }
//
// /**
// * Internal Encryption method.
// *
// * @param key - the SecretKeySpec used to encrypt
// * @param toEncrypt - the String to encrypt
// * @return the encrypted String (as byte[])
// */
// private byte[] encryptInternal(SecretKeySpec key, String toEncrypt) {
// try {
// Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM + ENCRYPTION_ALGORITHM_MODIFIER);
// cipher.init(Cipher.ENCRYPT_MODE, key);
// return cipher.doFinal(toEncrypt.getBytes(ENCODING));
// } catch (GeneralSecurityException e) {
// throw new RuntimeException("Exception during decryptInternal: " + e, e);
// } catch (UnsupportedEncodingException e) {
// throw new RuntimeException("Exception during encryptInternal: " + e, e);
// }
// }
//
// /**
// * Decrypt an encrypted and base64-encoded String
// *
// * @param toDecrypt - the encrypted and base64-encoded String
// * @return the plaintext String
// */
// public String decrypt(String toDecrypt) {
// byte[] encryptedBytes = base64Decoder.decode(toDecrypt);
// return decryptInternal(dataEncryptionSecretKeySpec, encryptedBytes);
// }
//
// /**
// * Internal decryption method.
// *
// * @param key - the SecretKeySpec used to decrypt
// * @param encryptedBytes - the byte[] to decrypt
// * @return the decrypted plaintext String.
// */
// private String decryptInternal(SecretKeySpec key, byte[] encryptedBytes) {
// try {
// Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM + ENCRYPTION_ALGORITHM_MODIFIER);
// cipher.init(Cipher.DECRYPT_MODE, key);
// byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
// return new String(decryptedBytes, ENCODING);
// } catch (GeneralSecurityException e) {
// throw new RuntimeException("Exception during decryptInternal: " + e, e);
// } catch (UnsupportedEncodingException e) {
// throw new RuntimeException("Exception during encryptInternal: " + e, e);
// }
// }
// }
// Path: src/main/java/com/tngtech/propertyloader/impl/filters/DecryptingFilter.java
import com.tngtech.propertyloader.Obfuscator;
import java.util.Properties;
package com.tngtech.propertyloader.impl.filters;
/**
* Decrypts property values that are prefixed with 'DECRYPT:'.
* The password must be provided in the properties, with key 'decryptingFilterPassword'
*/
public class DecryptingFilter extends ValueModifyingFilter {
public static final String DECRYPT_PREFIX = "DECRYPT:";
@Override
protected String filterValue(String key, String value, Properties properties) {
if (!value.startsWith(DECRYPT_PREFIX)) {
return value;
}
String encryptedValue = value.substring(DECRYPT_PREFIX.length());
String password = properties.getProperty("decryptingFilterPassword");
if (password == null) {
throw new DecryptingFilterException("Decryption failed: Password not found in properties");
}
| return new Obfuscator(password).decrypt(encryptedValue); |
TNG/property-loader | src/main/java/com/tngtech/propertyloader/impl/DefaultPropertyFilterContainer.java | // Path: src/main/java/com/tngtech/propertyloader/impl/interfaces/PropertyFilterContainer.java
// public interface PropertyFilterContainer<T> {
//
// T withDefaultFilters();
//
// T withVariableResolvingFilter();
//
// T withEnvironmentResolvingFilter();
//
// T withWarnIfPropertyHasToBeDefined();
//
// T withWarnOnSurroundingWhitespace();
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/interfaces/PropertyLoaderFilter.java
// public interface PropertyLoaderFilter {
//
// void filter(Properties properties);
// }
| import com.tngtech.propertyloader.impl.interfaces.PropertyFilterContainer;
import com.tngtech.propertyloader.impl.interfaces.PropertyLoaderFilter;
import java.util.ArrayList;
import java.util.List; | package com.tngtech.propertyloader.impl;
public class DefaultPropertyFilterContainer implements PropertyFilterContainer<DefaultPropertyFilterContainer> {
private final PropertyLoaderFactory propertyLoaderFactory;
| // Path: src/main/java/com/tngtech/propertyloader/impl/interfaces/PropertyFilterContainer.java
// public interface PropertyFilterContainer<T> {
//
// T withDefaultFilters();
//
// T withVariableResolvingFilter();
//
// T withEnvironmentResolvingFilter();
//
// T withWarnIfPropertyHasToBeDefined();
//
// T withWarnOnSurroundingWhitespace();
// }
//
// Path: src/main/java/com/tngtech/propertyloader/impl/interfaces/PropertyLoaderFilter.java
// public interface PropertyLoaderFilter {
//
// void filter(Properties properties);
// }
// Path: src/main/java/com/tngtech/propertyloader/impl/DefaultPropertyFilterContainer.java
import com.tngtech.propertyloader.impl.interfaces.PropertyFilterContainer;
import com.tngtech.propertyloader.impl.interfaces.PropertyLoaderFilter;
import java.util.ArrayList;
import java.util.List;
package com.tngtech.propertyloader.impl;
public class DefaultPropertyFilterContainer implements PropertyFilterContainer<DefaultPropertyFilterContainer> {
private final PropertyLoaderFactory propertyLoaderFactory;
| private final List<PropertyLoaderFilter> filters = new ArrayList<>(); |
TNG/property-loader | src/test/java/com/tngtech/propertyloader/impl/PropertyFileReaderTest.java | // Path: src/main/java/com/tngtech/propertyloader/impl/interfaces/PropertyLoaderOpener.java
// public interface PropertyLoaderOpener {
//
// /**
// * Attempt to find and open some property file.
// *
// * @param fileName A relative filename (using '/' as directory separator on all platforms)
// * @return An input stream reading from that file, or null if the file could not be found
// */
// InputStream open(String fileName);
// }
| import com.tngtech.propertyloader.impl.interfaces.PropertyLoaderOpener;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; | package com.tngtech.propertyloader.impl;
@RunWith(MockitoJUnitRunner.class)
public class PropertyFileReaderTest {
@Mock | // Path: src/main/java/com/tngtech/propertyloader/impl/interfaces/PropertyLoaderOpener.java
// public interface PropertyLoaderOpener {
//
// /**
// * Attempt to find and open some property file.
// *
// * @param fileName A relative filename (using '/' as directory separator on all platforms)
// * @return An input stream reading from that file, or null if the file could not be found
// */
// InputStream open(String fileName);
// }
// Path: src/test/java/com/tngtech/propertyloader/impl/PropertyFileReaderTest.java
import com.tngtech.propertyloader.impl.interfaces.PropertyLoaderOpener;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
package com.tngtech.propertyloader.impl;
@RunWith(MockitoJUnitRunner.class)
public class PropertyFileReaderTest {
@Mock | private PropertyLoaderOpener propertyLoaderOpener; |
searchisko/structured-content-tools | src/test/java/org/jboss/elasticsearch/tools/content/ESLookupValuePreprocessorTest.java | // Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/ESRealClientTestBase.java
// public abstract class ESRealClientTestBase {
//
// private Client client;
//
// private Node node;
//
// private File tempFolder;
//
// /**
// * Prepare ES inmemory client for unit test. Do not forgot to call {@link #finalizeESClientForUnitTest()} at the end
// * of test!
// *
// * @return
// * @throws Exception
// */
// public final Client prepareESClientForUnitTest() throws Exception {
// try {
// // For unit tests it is recommended to use local node.
// // This is to ensure that your node will never join existing cluster on the network.
//
// // path.data location
// tempFolder = new File("tmp");
// String tempFolderName = tempFolder.getCanonicalPath();
//
// if (tempFolder.exists()) {
// FileUtils.deleteDirectory(tempFolder);
// }
// if (!tempFolder.mkdir()) {
// throw new IOException("Could not create a temporary folder [" + tempFolderName + "]");
// }
//
// // Make sure that the index and metadata are not stored on the disk
// // path.data folder is created but we make sure it is removed after test finishes
// Settings settings = org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder()
// .put("index.store.type", "memory").put("gateway.type", "none").put("http.enabled", "false")
// .put("path.data", tempFolderName).build();
//
// node = NodeBuilder.nodeBuilder().settings(settings).local(true).node();
//
// client = node.client();
//
// return client;
// } catch (Exception e) {
// finalizeESClientForUnitTest();
// throw e;
// }
// }
//
// public final void finalizeESClientForUnitTest() {
// if (client != null)
// client.close();
// client = null;
// if (node != null)
// node.close();
// node = null;
//
// if (tempFolder != null && tempFolder.exists()) {
// try {
// FileUtils.deleteDirectory(tempFolder);
// } catch (IOException e) {
// // nothing to do
// }
// }
// tempFolder = null;
// }
//
// }
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
| import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.jboss.elasticsearch.tools.content.testtools.ESRealClientTestBase;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test;
import org.mockito.Mockito; | /*
* JBoss, Home of Professional Open Source
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
*/
package org.jboss.elasticsearch.tools.content;
/**
* Unit test for {@link ESLookupValuePreprocessor}.
*
* @author Vlastimil Elias (velias at redhat dot com)
*/
public class ESLookupValuePreprocessorTest extends ESRealClientTestBase {
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void init_settingerrors() {
ESLookupValuePreprocessor tested = new ESLookupValuePreprocessor();
Client client = Mockito.mock(Client.class);
// case - ES client mandatory
try { | // Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/ESRealClientTestBase.java
// public abstract class ESRealClientTestBase {
//
// private Client client;
//
// private Node node;
//
// private File tempFolder;
//
// /**
// * Prepare ES inmemory client for unit test. Do not forgot to call {@link #finalizeESClientForUnitTest()} at the end
// * of test!
// *
// * @return
// * @throws Exception
// */
// public final Client prepareESClientForUnitTest() throws Exception {
// try {
// // For unit tests it is recommended to use local node.
// // This is to ensure that your node will never join existing cluster on the network.
//
// // path.data location
// tempFolder = new File("tmp");
// String tempFolderName = tempFolder.getCanonicalPath();
//
// if (tempFolder.exists()) {
// FileUtils.deleteDirectory(tempFolder);
// }
// if (!tempFolder.mkdir()) {
// throw new IOException("Could not create a temporary folder [" + tempFolderName + "]");
// }
//
// // Make sure that the index and metadata are not stored on the disk
// // path.data folder is created but we make sure it is removed after test finishes
// Settings settings = org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder()
// .put("index.store.type", "memory").put("gateway.type", "none").put("http.enabled", "false")
// .put("path.data", tempFolderName).build();
//
// node = NodeBuilder.nodeBuilder().settings(settings).local(true).node();
//
// client = node.client();
//
// return client;
// } catch (Exception e) {
// finalizeESClientForUnitTest();
// throw e;
// }
// }
//
// public final void finalizeESClientForUnitTest() {
// if (client != null)
// client.close();
// client = null;
// if (node != null)
// node.close();
// node = null;
//
// if (tempFolder != null && tempFolder.exists()) {
// try {
// FileUtils.deleteDirectory(tempFolder);
// } catch (IOException e) {
// // nothing to do
// }
// }
// tempFolder = null;
// }
//
// }
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
// Path: src/test/java/org/jboss/elasticsearch/tools/content/ESLookupValuePreprocessorTest.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.jboss.elasticsearch.tools.content.testtools.ESRealClientTestBase;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test;
import org.mockito.Mockito;
/*
* JBoss, Home of Professional Open Source
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
*/
package org.jboss.elasticsearch.tools.content;
/**
* Unit test for {@link ESLookupValuePreprocessor}.
*
* @author Vlastimil Elias (velias at redhat dot com)
*/
public class ESLookupValuePreprocessorTest extends ESRealClientTestBase {
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void init_settingerrors() {
ESLookupValuePreprocessor tested = new ESLookupValuePreprocessor();
Client client = Mockito.mock(Client.class);
// case - ES client mandatory
try { | Map<String, Object> settings = TestUtils.loadJSONFromClasspathFile("/ESLookupValue_preprocessData-nobases.json"); |
searchisko/structured-content-tools | src/test/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessorTest.java | // Path: src/main/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessor.java
// public static enum HttpMethodType {
// GET, POST;
// }
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessor.java
// public static final class HttpResponseContent {
// public String contentType;
// public byte[] content;
//
// public HttpResponseContent(String contentType, byte[] content) {
// super();
// this.contentType = contentType;
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "HttpResponseContent [contentType=" + contentType + ", content=" + content != null ? new String(content) : "" + "]";
// }
//
// }
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
| import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.jboss.elasticsearch.tools.content.RESTCallPreprocessor.HttpMethodType;
import org.jboss.elasticsearch.tools.content.RESTCallPreprocessor.HttpResponseContent;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test;
import junit.framework.Assert; | /*
* JBoss, Home of Professional Open Source
* Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
*/
package org.jboss.elasticsearch.tools.content;
/**
* Unit test for {@link RESTCallPreprocessor}. It also contains <code>main</code> method for integration testing.
*
* @author Vlastimil Elias (velias at redhat dot com)
*/
public class RESTCallPreprocessorTest {
//private static final String INT_TEST_CONFIG = "/RESTCallPreprocessor_integrationTest_GET.json";
private static final String INT_TEST_CONFIG = "/RESTCallPreprocessor_integrationTest_POST.json";
public static void main(String[] args) {
RESTCallPreprocessor tested = getTested(); | // Path: src/main/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessor.java
// public static enum HttpMethodType {
// GET, POST;
// }
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessor.java
// public static final class HttpResponseContent {
// public String contentType;
// public byte[] content;
//
// public HttpResponseContent(String contentType, byte[] content) {
// super();
// this.contentType = contentType;
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "HttpResponseContent [contentType=" + contentType + ", content=" + content != null ? new String(content) : "" + "]";
// }
//
// }
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
// Path: src/test/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessorTest.java
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.jboss.elasticsearch.tools.content.RESTCallPreprocessor.HttpMethodType;
import org.jboss.elasticsearch.tools.content.RESTCallPreprocessor.HttpResponseContent;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test;
import junit.framework.Assert;
/*
* JBoss, Home of Professional Open Source
* Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
*/
package org.jboss.elasticsearch.tools.content;
/**
* Unit test for {@link RESTCallPreprocessor}. It also contains <code>main</code> method for integration testing.
*
* @author Vlastimil Elias (velias at redhat dot com)
*/
public class RESTCallPreprocessorTest {
//private static final String INT_TEST_CONFIG = "/RESTCallPreprocessor_integrationTest_GET.json";
private static final String INT_TEST_CONFIG = "/RESTCallPreprocessor_integrationTest_POST.json";
public static void main(String[] args) {
RESTCallPreprocessor tested = getTested(); | Map<String, Object> settings = TestUtils.loadJSONFromClasspathFile(INT_TEST_CONFIG); |
searchisko/structured-content-tools | src/test/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessorTest.java | // Path: src/main/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessor.java
// public static enum HttpMethodType {
// GET, POST;
// }
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessor.java
// public static final class HttpResponseContent {
// public String contentType;
// public byte[] content;
//
// public HttpResponseContent(String contentType, byte[] content) {
// super();
// this.contentType = contentType;
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "HttpResponseContent [contentType=" + contentType + ", content=" + content != null ? new String(content) : "" + "]";
// }
//
// }
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
| import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.jboss.elasticsearch.tools.content.RESTCallPreprocessor.HttpMethodType;
import org.jboss.elasticsearch.tools.content.RESTCallPreprocessor.HttpResponseContent;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test;
import junit.framework.Assert; | /*
* JBoss, Home of Professional Open Source
* Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
*/
package org.jboss.elasticsearch.tools.content;
/**
* Unit test for {@link RESTCallPreprocessor}. It also contains <code>main</code> method for integration testing.
*
* @author Vlastimil Elias (velias at redhat dot com)
*/
public class RESTCallPreprocessorTest {
//private static final String INT_TEST_CONFIG = "/RESTCallPreprocessor_integrationTest_GET.json";
private static final String INT_TEST_CONFIG = "/RESTCallPreprocessor_integrationTest_POST.json";
public static void main(String[] args) {
RESTCallPreprocessor tested = getTested();
Map<String, Object> settings = TestUtils.loadJSONFromClasspathFile(INT_TEST_CONFIG);
tested.init(settings);
Map<String, Object> data = new HashMap<>();
data.put("id", "JBEAP-2377");
data.put("type", "p&2\"aa");
tested.preprocessData(data, new PreprocessChainContext() {
@Override
public void addDataWarning(String preprocessorName, String warningMessage) throws IllegalArgumentException {
System.out.println(warningMessage);
}
} );
tested.logger.info("Data after integration test {}", data);
}
@Test
public void prepareContent(){
RESTCallPreprocessor tested = getTested();
tested.request_content_template = "{ \"test\" : \"$val$\", \"test2\":\"$val2.val$\"}";
//always null for GET | // Path: src/main/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessor.java
// public static enum HttpMethodType {
// GET, POST;
// }
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessor.java
// public static final class HttpResponseContent {
// public String contentType;
// public byte[] content;
//
// public HttpResponseContent(String contentType, byte[] content) {
// super();
// this.contentType = contentType;
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "HttpResponseContent [contentType=" + contentType + ", content=" + content != null ? new String(content) : "" + "]";
// }
//
// }
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
// Path: src/test/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessorTest.java
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.jboss.elasticsearch.tools.content.RESTCallPreprocessor.HttpMethodType;
import org.jboss.elasticsearch.tools.content.RESTCallPreprocessor.HttpResponseContent;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test;
import junit.framework.Assert;
/*
* JBoss, Home of Professional Open Source
* Copyright 2017 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
*/
package org.jboss.elasticsearch.tools.content;
/**
* Unit test for {@link RESTCallPreprocessor}. It also contains <code>main</code> method for integration testing.
*
* @author Vlastimil Elias (velias at redhat dot com)
*/
public class RESTCallPreprocessorTest {
//private static final String INT_TEST_CONFIG = "/RESTCallPreprocessor_integrationTest_GET.json";
private static final String INT_TEST_CONFIG = "/RESTCallPreprocessor_integrationTest_POST.json";
public static void main(String[] args) {
RESTCallPreprocessor tested = getTested();
Map<String, Object> settings = TestUtils.loadJSONFromClasspathFile(INT_TEST_CONFIG);
tested.init(settings);
Map<String, Object> data = new HashMap<>();
data.put("id", "JBEAP-2377");
data.put("type", "p&2\"aa");
tested.preprocessData(data, new PreprocessChainContext() {
@Override
public void addDataWarning(String preprocessorName, String warningMessage) throws IllegalArgumentException {
System.out.println(warningMessage);
}
} );
tested.logger.info("Data after integration test {}", data);
}
@Test
public void prepareContent(){
RESTCallPreprocessor tested = getTested();
tested.request_content_template = "{ \"test\" : \"$val$\", \"test2\":\"$val2.val$\"}";
//always null for GET | tested.request_method = HttpMethodType.GET; |
searchisko/structured-content-tools | src/test/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessorTest.java | // Path: src/main/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessor.java
// public static enum HttpMethodType {
// GET, POST;
// }
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessor.java
// public static final class HttpResponseContent {
// public String contentType;
// public byte[] content;
//
// public HttpResponseContent(String contentType, byte[] content) {
// super();
// this.contentType = contentType;
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "HttpResponseContent [contentType=" + contentType + ", content=" + content != null ? new String(content) : "" + "]";
// }
//
// }
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
| import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.jboss.elasticsearch.tools.content.RESTCallPreprocessor.HttpMethodType;
import org.jboss.elasticsearch.tools.content.RESTCallPreprocessor.HttpResponseContent;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test;
import junit.framework.Assert; | //we also test JSON encoding there!!
data.put("val", "aha\" aha");
StructureUtils.putValueIntoMapOfMaps(data, "val2.val", "jo \\ jo");
Assert.assertEquals("{ \"test\" : \"aha\\\" aha\", \"test2\":\"jo \\\\ jo\"}", tested.prepareContent(data ));
}
@Test
public void prepareUrl(){
RESTCallPreprocessor tested = getTested();
tested.request_url = "http://test.org/api/method?param1={val}¶m2={val2.val}";
Assert.assertEquals("http://test.org/api/method?param1=¶m2=", tested.prepareUrl(null));
Map<String, Object> data = new HashMap<>();
//we also test URL encoding there!!
data.put("val", "aha&aha");
StructureUtils.putValueIntoMapOfMaps(data, "val2.val", "jo&jo");
Assert.assertEquals("http://test.org/api/method?param1=aha%26aha¶m2=jo%26jo", tested.prepareUrl(data));
}
@SuppressWarnings("unchecked")
@Test
public void processResponse_no_response_data() throws Exception{
RESTCallPreprocessor tested = getTested();
tested.responseMapping = (List<Map<String, String>>) TestUtils.loadJSONFromClasspathFile("/RESTCallPreprocessor_settings_correct_with_defaults.json").get(RESTCallPreprocessor.CFG_RESPONSE_MAPPING);
Map<String, Object> data = new HashMap<>();
byte[] content = new byte[]{}; | // Path: src/main/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessor.java
// public static enum HttpMethodType {
// GET, POST;
// }
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessor.java
// public static final class HttpResponseContent {
// public String contentType;
// public byte[] content;
//
// public HttpResponseContent(String contentType, byte[] content) {
// super();
// this.contentType = contentType;
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "HttpResponseContent [contentType=" + contentType + ", content=" + content != null ? new String(content) : "" + "]";
// }
//
// }
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
// Path: src/test/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessorTest.java
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.jboss.elasticsearch.tools.content.RESTCallPreprocessor.HttpMethodType;
import org.jboss.elasticsearch.tools.content.RESTCallPreprocessor.HttpResponseContent;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test;
import junit.framework.Assert;
//we also test JSON encoding there!!
data.put("val", "aha\" aha");
StructureUtils.putValueIntoMapOfMaps(data, "val2.val", "jo \\ jo");
Assert.assertEquals("{ \"test\" : \"aha\\\" aha\", \"test2\":\"jo \\\\ jo\"}", tested.prepareContent(data ));
}
@Test
public void prepareUrl(){
RESTCallPreprocessor tested = getTested();
tested.request_url = "http://test.org/api/method?param1={val}¶m2={val2.val}";
Assert.assertEquals("http://test.org/api/method?param1=¶m2=", tested.prepareUrl(null));
Map<String, Object> data = new HashMap<>();
//we also test URL encoding there!!
data.put("val", "aha&aha");
StructureUtils.putValueIntoMapOfMaps(data, "val2.val", "jo&jo");
Assert.assertEquals("http://test.org/api/method?param1=aha%26aha¶m2=jo%26jo", tested.prepareUrl(data));
}
@SuppressWarnings("unchecked")
@Test
public void processResponse_no_response_data() throws Exception{
RESTCallPreprocessor tested = getTested();
tested.responseMapping = (List<Map<String, String>>) TestUtils.loadJSONFromClasspathFile("/RESTCallPreprocessor_settings_correct_with_defaults.json").get(RESTCallPreprocessor.CFG_RESPONSE_MAPPING);
Map<String, Object> data = new HashMap<>();
byte[] content = new byte[]{}; | HttpResponseContent response = new HttpResponseContent("ct", content ); |
searchisko/structured-content-tools | src/main/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessor.java | // Path: src/main/java/org/jboss/elasticsearch/tools/content/ValueUtils.java
// public static interface IValueEncoder {
// public String encode(Object value);
// }
| import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.HttpStatus;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.config.ConnectionConfig;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.util.EntityUtils;
import org.elasticsearch.common.jackson.core.io.JsonStringEncoder;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.jboss.elasticsearch.tools.content.ValueUtils.IValueEncoder; | if (logger.isDebugEnabled())
logger.debug("Parsed ResponseData: {}", responseParsed);
if (logger.isDebugEnabled())
logger.debug("Data before processing: {}", data);
for (Map<String, String> mappingRecord : responseMapping) {
String restResponseField = mappingRecord.get(CFG_rest_response_field);
Object v = null;
if ("_source".equals(restResponseField)) {
v = responseParsed;
} else {
if (restResponseField.contains(".")) {
v = XContentMapValues.extractValue(restResponseField, responseParsed);
} else {
v = responseParsed.get(restResponseField);
}
}
if (v == null && mappingRecord.get(CFG_value_default) != null) {
v = ValueUtils.processStringValuePatternReplacement(mappingRecord.get(CFG_value_default), data, null);
}
StructureUtils.putValueIntoMapOfMaps(data, mappingRecord.get(CFG_target_field), v);
}
if (logger.isDebugEnabled())
logger.debug("Data after processing: {}", data);
}
| // Path: src/main/java/org/jboss/elasticsearch/tools/content/ValueUtils.java
// public static interface IValueEncoder {
// public String encode(Object value);
// }
// Path: src/main/java/org/jboss/elasticsearch/tools/content/RESTCallPreprocessor.java
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.HttpStatus;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.config.ConnectionConfig;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.util.EntityUtils;
import org.elasticsearch.common.jackson.core.io.JsonStringEncoder;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.jboss.elasticsearch.tools.content.ValueUtils.IValueEncoder;
if (logger.isDebugEnabled())
logger.debug("Parsed ResponseData: {}", responseParsed);
if (logger.isDebugEnabled())
logger.debug("Data before processing: {}", data);
for (Map<String, String> mappingRecord : responseMapping) {
String restResponseField = mappingRecord.get(CFG_rest_response_field);
Object v = null;
if ("_source".equals(restResponseField)) {
v = responseParsed;
} else {
if (restResponseField.contains(".")) {
v = XContentMapValues.extractValue(restResponseField, responseParsed);
} else {
v = responseParsed.get(restResponseField);
}
}
if (v == null && mappingRecord.get(CFG_value_default) != null) {
v = ValueUtils.processStringValuePatternReplacement(mappingRecord.get(CFG_value_default), data, null);
}
StructureUtils.putValueIntoMapOfMaps(data, mappingRecord.get(CFG_target_field), v);
}
if (logger.isDebugEnabled())
logger.debug("Data after processing: {}", data);
}
| protected static final IValueEncoder jsonValueEncoder = new IValueEncoder() { |
searchisko/structured-content-tools | src/test/java/org/jboss/elasticsearch/tools/content/ValuesCollectingPreprocessorTest.java | // Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
| import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test; |
// case - no more mandatory setting fields
settings.put(ValuesCollectingPreprocessor.CFG_TARGET_FIELD, "target");
tested.init("Test mapper", null, settings);
}
@Test
public void init() {
ValuesCollectingPreprocessor tested = new ValuesCollectingPreprocessor();
// case - mandatory fields only
Map<String, Object> settings = new HashMap<String, Object>();
List<Object> sources = new ArrayList<Object>();
sources.add("source1");
sources.add("source2");
settings.put(ValuesCollectingPreprocessor.CFG_SOURCE_FIELDS, sources);
settings.put(ValuesCollectingPreprocessor.CFG_TARGET_FIELD, "target");
tested.init("Test mapper", null, settings);
Assert.assertEquals("Test mapper", tested.getName());
Assert.assertEquals(2, tested.fieldsSource.size());
Assert.assertTrue(tested.fieldsSource.contains("source1"));
Assert.assertTrue(tested.fieldsSource.contains("source2"));
Assert.assertEquals("target", tested.fieldTarget);
}
@SuppressWarnings("unchecked")
@Test
public void preprocessData() {
ValuesCollectingPreprocessor tested = new ValuesCollectingPreprocessor(); | // Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
// Path: src/test/java/org/jboss/elasticsearch/tools/content/ValuesCollectingPreprocessorTest.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test;
// case - no more mandatory setting fields
settings.put(ValuesCollectingPreprocessor.CFG_TARGET_FIELD, "target");
tested.init("Test mapper", null, settings);
}
@Test
public void init() {
ValuesCollectingPreprocessor tested = new ValuesCollectingPreprocessor();
// case - mandatory fields only
Map<String, Object> settings = new HashMap<String, Object>();
List<Object> sources = new ArrayList<Object>();
sources.add("source1");
sources.add("source2");
settings.put(ValuesCollectingPreprocessor.CFG_SOURCE_FIELDS, sources);
settings.put(ValuesCollectingPreprocessor.CFG_TARGET_FIELD, "target");
tested.init("Test mapper", null, settings);
Assert.assertEquals("Test mapper", tested.getName());
Assert.assertEquals(2, tested.fieldsSource.size());
Assert.assertTrue(tested.fieldsSource.contains("source1"));
Assert.assertTrue(tested.fieldsSource.contains("source2"));
Assert.assertEquals("target", tested.fieldTarget);
}
@SuppressWarnings("unchecked")
@Test
public void preprocessData() {
ValuesCollectingPreprocessor tested = new ValuesCollectingPreprocessor(); | tested.init("Test mapper", null, TestUtils.loadJSONFromClasspathFile("/ValuesCollecting_preprocessData.json")); |
searchisko/structured-content-tools | src/test/java/org/jboss/elasticsearch/tools/content/StructuredContentPreprocessorWithSourceBasesBaseTest.java | // Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
| import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.settings.SettingsException;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito; | Mockito.doCallRealMethod().when(tested).preprocessData(Mockito.anyMap(), Mockito.any(PreprocessChainContext.class));
Mockito.doCallRealMethod().when(tested).getSourceBases();
Map<String, Object> settings = new HashMap<String, Object>();
tested.init(settings);
Map<String, Object> data = new HashMap<String, Object>();
Assert.assertEquals(data, tested.preprocessData(data, null));
Mockito.verify(tested).init(settings);
Mockito.verify(tested).preprocessData(data, null);
Mockito.verify(tested).processOneSourceValue(data, null, null, null);
Mockito.verify(tested, Mockito.times(0)).createContext(Mockito.anyMap());
Mockito.verifyNoMoreInteractions(tested);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void preprocessData_bases() {
StructuredContentPreprocessorWithSourceBasesBase tested = Mockito
.mock(StructuredContentPreprocessorWithSourceBasesBase.class);
tested.name = "mypreproc";
Mockito.doCallRealMethod().when(tested).init(Mockito.anyMap());
Mockito.doCallRealMethod().when(tested).preprocessData(Mockito.anyMap(), Mockito.any(PreprocessChainContext.class));
Mockito.doCallRealMethod().when(tested).getSourceBases();
Mockito.doCallRealMethod().when(tested)
.addDataWarning(Mockito.any(PreprocessChainContext.class), Mockito.anyString());
tested.logger = Mockito.mock(ESLogger.class);
Object mockContext = new Object();
Mockito.when(tested.createContext(Mockito.anyMap())).thenReturn(mockContext);
| // Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
// Path: src/test/java/org/jboss/elasticsearch/tools/content/StructuredContentPreprocessorWithSourceBasesBaseTest.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.settings.SettingsException;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
Mockito.doCallRealMethod().when(tested).preprocessData(Mockito.anyMap(), Mockito.any(PreprocessChainContext.class));
Mockito.doCallRealMethod().when(tested).getSourceBases();
Map<String, Object> settings = new HashMap<String, Object>();
tested.init(settings);
Map<String, Object> data = new HashMap<String, Object>();
Assert.assertEquals(data, tested.preprocessData(data, null));
Mockito.verify(tested).init(settings);
Mockito.verify(tested).preprocessData(data, null);
Mockito.verify(tested).processOneSourceValue(data, null, null, null);
Mockito.verify(tested, Mockito.times(0)).createContext(Mockito.anyMap());
Mockito.verifyNoMoreInteractions(tested);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void preprocessData_bases() {
StructuredContentPreprocessorWithSourceBasesBase tested = Mockito
.mock(StructuredContentPreprocessorWithSourceBasesBase.class);
tested.name = "mypreproc";
Mockito.doCallRealMethod().when(tested).init(Mockito.anyMap());
Mockito.doCallRealMethod().when(tested).preprocessData(Mockito.anyMap(), Mockito.any(PreprocessChainContext.class));
Mockito.doCallRealMethod().when(tested).getSourceBases();
Mockito.doCallRealMethod().when(tested)
.addDataWarning(Mockito.any(PreprocessChainContext.class), Mockito.anyString());
tested.logger = Mockito.mock(ESLogger.class);
Object mockContext = new Object();
Mockito.when(tested.createContext(Mockito.anyMap())).thenReturn(mockContext);
| Map<String, Object> settings = TestUtils.loadJSONFromClasspathFile("/ESLookupValue_preprocessData-bases.json"); |
searchisko/structured-content-tools | src/test/java/org/jboss/elasticsearch/tools/content/StructuredContentPreprocessorFactoryTest.java | // Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
| import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.client.Client;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test;
import static org.mockito.Mockito.mock; | }
@Test(expected = IllegalArgumentException.class)
public void createPreprocessor_class_unknown() {
Client clientMock = mock(Client.class);
Map<String, Object> preprocessorConfig = getTestingPreprocessorConfig();
preprocessorConfig.put(StructuredContentPreprocessorFactory.CFG_CLASS, "org.unknown.Test");
StructuredContentPreprocessorFactory.createPreprocessor(preprocessorConfig, clientMock);
}
@Test(expected = IllegalArgumentException.class)
public void createPreprocessor_class_badtype() {
Client clientMock = mock(Client.class);
Map<String, Object> preprocessorConfig = getTestingPreprocessorConfig();
preprocessorConfig.put(StructuredContentPreprocessorFactory.CFG_CLASS, "java.lang.String");
StructuredContentPreprocessorFactory.createPreprocessor(preprocessorConfig, clientMock);
}
@Test(expected = IllegalArgumentException.class)
public void createPreprocessor_settings_badtype() {
Client clientMock = mock(Client.class);
Map<String, Object> preprocessorConfig = getTestingPreprocessorConfig();
preprocessorConfig.put(StructuredContentPreprocessorFactory.CFG_SETTINGS, "");
StructuredContentPreprocessorFactory.createPreprocessor(preprocessorConfig, clientMock);
}
@SuppressWarnings("unchecked")
private Map<String, Object> getTestingPreprocessorConfig() { | // Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
// Path: src/test/java/org/jboss/elasticsearch/tools/content/StructuredContentPreprocessorFactoryTest.java
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.client.Client;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test;
import static org.mockito.Mockito.mock;
}
@Test(expected = IllegalArgumentException.class)
public void createPreprocessor_class_unknown() {
Client clientMock = mock(Client.class);
Map<String, Object> preprocessorConfig = getTestingPreprocessorConfig();
preprocessorConfig.put(StructuredContentPreprocessorFactory.CFG_CLASS, "org.unknown.Test");
StructuredContentPreprocessorFactory.createPreprocessor(preprocessorConfig, clientMock);
}
@Test(expected = IllegalArgumentException.class)
public void createPreprocessor_class_badtype() {
Client clientMock = mock(Client.class);
Map<String, Object> preprocessorConfig = getTestingPreprocessorConfig();
preprocessorConfig.put(StructuredContentPreprocessorFactory.CFG_CLASS, "java.lang.String");
StructuredContentPreprocessorFactory.createPreprocessor(preprocessorConfig, clientMock);
}
@Test(expected = IllegalArgumentException.class)
public void createPreprocessor_settings_badtype() {
Client clientMock = mock(Client.class);
Map<String, Object> preprocessorConfig = getTestingPreprocessorConfig();
preprocessorConfig.put(StructuredContentPreprocessorFactory.CFG_SETTINGS, "");
StructuredContentPreprocessorFactory.createPreprocessor(preprocessorConfig, clientMock);
}
@SuppressWarnings("unchecked")
private Map<String, Object> getTestingPreprocessorConfig() { | List<Map<String, Object>> preprocessorConfigList = (List<Map<String, Object>>) (TestUtils |
searchisko/structured-content-tools | src/test/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessorTest.java | // Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_CHECKED_DATE = "checked_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_DEFAULT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSXX";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_LEFT_DATE = "left_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RESULT_FIELD = "result_field";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RIGHT_DATE = "right_date";
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
| import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_CHECKED_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_DEFAULT_DATE_FORMAT;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_LEFT_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RESULT_FIELD;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RIGHT_DATE;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.common.settings.SettingsException;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test; | /*
* JBoss, Home of Professional Open Source
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
*/
package org.jboss.elasticsearch.tools.content;
/**
* Unit tests for {@link IsDateInRangePreprocessor}.
*
* @author Ryszard Kozmik (rkozmik at redhat dot com)
*/
public class IsDateInRangePreprocessorTest {
@Test
public void init_settingerrors() {
IsDateInRangePreprocessor tested = new IsDateInRangePreprocessor();
Map<String, Object> settings = null;
// case - settings mandatory
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals("'settings' section is not defined for preprocessor Test mapper", e.getMessage());
}
// case - source_field mandatory
settings = new HashMap<String, Object>();
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals( | // Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_CHECKED_DATE = "checked_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_DEFAULT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSXX";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_LEFT_DATE = "left_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RESULT_FIELD = "result_field";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RIGHT_DATE = "right_date";
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
// Path: src/test/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessorTest.java
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_CHECKED_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_DEFAULT_DATE_FORMAT;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_LEFT_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RESULT_FIELD;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RIGHT_DATE;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.common.settings.SettingsException;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test;
/*
* JBoss, Home of Professional Open Source
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
*/
package org.jboss.elasticsearch.tools.content;
/**
* Unit tests for {@link IsDateInRangePreprocessor}.
*
* @author Ryszard Kozmik (rkozmik at redhat dot com)
*/
public class IsDateInRangePreprocessorTest {
@Test
public void init_settingerrors() {
IsDateInRangePreprocessor tested = new IsDateInRangePreprocessor();
Map<String, Object> settings = null;
// case - settings mandatory
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals("'settings' section is not defined for preprocessor Test mapper", e.getMessage());
}
// case - source_field mandatory
settings = new HashMap<String, Object>();
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals( | "Missing or empty 'settings/"+CFG_CHECKED_DATE+"' configuration value for 'Test mapper' preprocessor", |
searchisko/structured-content-tools | src/test/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessorTest.java | // Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_CHECKED_DATE = "checked_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_DEFAULT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSXX";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_LEFT_DATE = "left_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RESULT_FIELD = "result_field";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RIGHT_DATE = "right_date";
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
| import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_CHECKED_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_DEFAULT_DATE_FORMAT;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_LEFT_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RESULT_FIELD;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RIGHT_DATE;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.common.settings.SettingsException;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test; | /*
* JBoss, Home of Professional Open Source
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
*/
package org.jboss.elasticsearch.tools.content;
/**
* Unit tests for {@link IsDateInRangePreprocessor}.
*
* @author Ryszard Kozmik (rkozmik at redhat dot com)
*/
public class IsDateInRangePreprocessorTest {
@Test
public void init_settingerrors() {
IsDateInRangePreprocessor tested = new IsDateInRangePreprocessor();
Map<String, Object> settings = null;
// case - settings mandatory
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals("'settings' section is not defined for preprocessor Test mapper", e.getMessage());
}
// case - source_field mandatory
settings = new HashMap<String, Object>();
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals(
"Missing or empty 'settings/"+CFG_CHECKED_DATE+"' configuration value for 'Test mapper' preprocessor",
e.getMessage());
}
// case - result_field mandatory
settings.put(CFG_CHECKED_DATE, "tested_date");
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals( | // Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_CHECKED_DATE = "checked_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_DEFAULT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSXX";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_LEFT_DATE = "left_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RESULT_FIELD = "result_field";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RIGHT_DATE = "right_date";
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
// Path: src/test/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessorTest.java
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_CHECKED_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_DEFAULT_DATE_FORMAT;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_LEFT_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RESULT_FIELD;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RIGHT_DATE;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.common.settings.SettingsException;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test;
/*
* JBoss, Home of Professional Open Source
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
*/
package org.jboss.elasticsearch.tools.content;
/**
* Unit tests for {@link IsDateInRangePreprocessor}.
*
* @author Ryszard Kozmik (rkozmik at redhat dot com)
*/
public class IsDateInRangePreprocessorTest {
@Test
public void init_settingerrors() {
IsDateInRangePreprocessor tested = new IsDateInRangePreprocessor();
Map<String, Object> settings = null;
// case - settings mandatory
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals("'settings' section is not defined for preprocessor Test mapper", e.getMessage());
}
// case - source_field mandatory
settings = new HashMap<String, Object>();
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals(
"Missing or empty 'settings/"+CFG_CHECKED_DATE+"' configuration value for 'Test mapper' preprocessor",
e.getMessage());
}
// case - result_field mandatory
settings.put(CFG_CHECKED_DATE, "tested_date");
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals( | "Missing or empty 'settings/"+CFG_RESULT_FIELD+"' configuration value for 'Test mapper' preprocessor", |
searchisko/structured-content-tools | src/test/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessorTest.java | // Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_CHECKED_DATE = "checked_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_DEFAULT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSXX";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_LEFT_DATE = "left_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RESULT_FIELD = "result_field";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RIGHT_DATE = "right_date";
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
| import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_CHECKED_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_DEFAULT_DATE_FORMAT;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_LEFT_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RESULT_FIELD;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RIGHT_DATE;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.common.settings.SettingsException;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test; |
// case - source_field mandatory
settings = new HashMap<String, Object>();
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals(
"Missing or empty 'settings/"+CFG_CHECKED_DATE+"' configuration value for 'Test mapper' preprocessor",
e.getMessage());
}
// case - result_field mandatory
settings.put(CFG_CHECKED_DATE, "tested_date");
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals(
"Missing or empty 'settings/"+CFG_RESULT_FIELD+"' configuration value for 'Test mapper' preprocessor",
e.getMessage());
}
// case - at least one of left_date or right_date must be provided
settings.put(CFG_RESULT_FIELD, "target");
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals( | // Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_CHECKED_DATE = "checked_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_DEFAULT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSXX";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_LEFT_DATE = "left_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RESULT_FIELD = "result_field";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RIGHT_DATE = "right_date";
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
// Path: src/test/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessorTest.java
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_CHECKED_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_DEFAULT_DATE_FORMAT;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_LEFT_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RESULT_FIELD;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RIGHT_DATE;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.common.settings.SettingsException;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test;
// case - source_field mandatory
settings = new HashMap<String, Object>();
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals(
"Missing or empty 'settings/"+CFG_CHECKED_DATE+"' configuration value for 'Test mapper' preprocessor",
e.getMessage());
}
// case - result_field mandatory
settings.put(CFG_CHECKED_DATE, "tested_date");
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals(
"Missing or empty 'settings/"+CFG_RESULT_FIELD+"' configuration value for 'Test mapper' preprocessor",
e.getMessage());
}
// case - at least one of left_date or right_date must be provided
settings.put(CFG_RESULT_FIELD, "target");
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals( | "At least one of dates defining range, settings/"+CFG_LEFT_DATE+" or settings/"+CFG_RIGHT_DATE+" need to be provided.", |
searchisko/structured-content-tools | src/test/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessorTest.java | // Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_CHECKED_DATE = "checked_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_DEFAULT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSXX";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_LEFT_DATE = "left_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RESULT_FIELD = "result_field";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RIGHT_DATE = "right_date";
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
| import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_CHECKED_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_DEFAULT_DATE_FORMAT;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_LEFT_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RESULT_FIELD;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RIGHT_DATE;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.common.settings.SettingsException;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test; |
// case - source_field mandatory
settings = new HashMap<String, Object>();
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals(
"Missing or empty 'settings/"+CFG_CHECKED_DATE+"' configuration value for 'Test mapper' preprocessor",
e.getMessage());
}
// case - result_field mandatory
settings.put(CFG_CHECKED_DATE, "tested_date");
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals(
"Missing or empty 'settings/"+CFG_RESULT_FIELD+"' configuration value for 'Test mapper' preprocessor",
e.getMessage());
}
// case - at least one of left_date or right_date must be provided
settings.put(CFG_RESULT_FIELD, "target");
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals( | // Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_CHECKED_DATE = "checked_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_DEFAULT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSXX";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_LEFT_DATE = "left_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RESULT_FIELD = "result_field";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RIGHT_DATE = "right_date";
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
// Path: src/test/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessorTest.java
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_CHECKED_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_DEFAULT_DATE_FORMAT;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_LEFT_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RESULT_FIELD;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RIGHT_DATE;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.common.settings.SettingsException;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test;
// case - source_field mandatory
settings = new HashMap<String, Object>();
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals(
"Missing or empty 'settings/"+CFG_CHECKED_DATE+"' configuration value for 'Test mapper' preprocessor",
e.getMessage());
}
// case - result_field mandatory
settings.put(CFG_CHECKED_DATE, "tested_date");
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals(
"Missing or empty 'settings/"+CFG_RESULT_FIELD+"' configuration value for 'Test mapper' preprocessor",
e.getMessage());
}
// case - at least one of left_date or right_date must be provided
settings.put(CFG_RESULT_FIELD, "target");
try {
tested.init("Test mapper", null, settings);
Assert.fail("SettingsException must be thrown");
} catch (SettingsException e) {
Assert.assertEquals( | "At least one of dates defining range, settings/"+CFG_LEFT_DATE+" or settings/"+CFG_RIGHT_DATE+" need to be provided.", |
searchisko/structured-content-tools | src/test/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessorTest.java | // Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_CHECKED_DATE = "checked_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_DEFAULT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSXX";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_LEFT_DATE = "left_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RESULT_FIELD = "result_field";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RIGHT_DATE = "right_date";
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
| import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_CHECKED_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_DEFAULT_DATE_FORMAT;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_LEFT_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RESULT_FIELD;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RIGHT_DATE;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.common.settings.SettingsException;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test; | Assert.assertEquals(
"At least one of dates defining range, settings/"+CFG_LEFT_DATE+" or settings/"+CFG_RIGHT_DATE+" need to be provided.",
e.getMessage());
}
// case - no more mandatory setting fields
settings.put(CFG_RIGHT_DATE, "right_date");
tested.init("Test mapper", null, settings);
}
@Test
public void init() {
// case - mandatory fields only filled in
IsDateInRangePreprocessor tested = new IsDateInRangePreprocessor();
Map<String, Object> settings = new HashMap<String, Object>();
settings.put( CFG_CHECKED_DATE, "tested_date" );
settings.put( CFG_RESULT_FIELD, "target" );
settings.put( CFG_LEFT_DATE, "left_date" );
tested.init( "Test mapper", null, settings );
Assert.assertEquals( "Test mapper", tested.getName() );
Assert.assertEquals( "tested_date", tested.checkedDateField );
Assert.assertEquals( "target" , tested.resultField );
Assert.assertEquals( "left_date" , tested.leftDateField );
Assert.assertNull( tested.rightDateField );
Assert.assertNull( tested.sourceBases );
// Checking if default date format is used if not provided
Assert.assertNotNull( tested.leftDateFormat ); | // Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_CHECKED_DATE = "checked_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_DEFAULT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSXX";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_LEFT_DATE = "left_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RESULT_FIELD = "result_field";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RIGHT_DATE = "right_date";
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
// Path: src/test/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessorTest.java
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_CHECKED_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_DEFAULT_DATE_FORMAT;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_LEFT_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RESULT_FIELD;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RIGHT_DATE;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.common.settings.SettingsException;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test;
Assert.assertEquals(
"At least one of dates defining range, settings/"+CFG_LEFT_DATE+" or settings/"+CFG_RIGHT_DATE+" need to be provided.",
e.getMessage());
}
// case - no more mandatory setting fields
settings.put(CFG_RIGHT_DATE, "right_date");
tested.init("Test mapper", null, settings);
}
@Test
public void init() {
// case - mandatory fields only filled in
IsDateInRangePreprocessor tested = new IsDateInRangePreprocessor();
Map<String, Object> settings = new HashMap<String, Object>();
settings.put( CFG_CHECKED_DATE, "tested_date" );
settings.put( CFG_RESULT_FIELD, "target" );
settings.put( CFG_LEFT_DATE, "left_date" );
tested.init( "Test mapper", null, settings );
Assert.assertEquals( "Test mapper", tested.getName() );
Assert.assertEquals( "tested_date", tested.checkedDateField );
Assert.assertEquals( "target" , tested.resultField );
Assert.assertEquals( "left_date" , tested.leftDateField );
Assert.assertNull( tested.rightDateField );
Assert.assertNull( tested.sourceBases );
// Checking if default date format is used if not provided
Assert.assertNotNull( tested.leftDateFormat ); | Assert.assertEquals( CFG_DEFAULT_DATE_FORMAT , tested.leftDateFormat ); |
searchisko/structured-content-tools | src/test/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessorTest.java | // Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_CHECKED_DATE = "checked_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_DEFAULT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSXX";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_LEFT_DATE = "left_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RESULT_FIELD = "result_field";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RIGHT_DATE = "right_date";
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
| import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_CHECKED_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_DEFAULT_DATE_FORMAT;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_LEFT_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RESULT_FIELD;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RIGHT_DATE;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.common.settings.SettingsException;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test; | }
@Test
public void init() {
// case - mandatory fields only filled in
IsDateInRangePreprocessor tested = new IsDateInRangePreprocessor();
Map<String, Object> settings = new HashMap<String, Object>();
settings.put( CFG_CHECKED_DATE, "tested_date" );
settings.put( CFG_RESULT_FIELD, "target" );
settings.put( CFG_LEFT_DATE, "left_date" );
tested.init( "Test mapper", null, settings );
Assert.assertEquals( "Test mapper", tested.getName() );
Assert.assertEquals( "tested_date", tested.checkedDateField );
Assert.assertEquals( "target" , tested.resultField );
Assert.assertEquals( "left_date" , tested.leftDateField );
Assert.assertNull( tested.rightDateField );
Assert.assertNull( tested.sourceBases );
// Checking if default date format is used if not provided
Assert.assertNotNull( tested.leftDateFormat );
Assert.assertEquals( CFG_DEFAULT_DATE_FORMAT , tested.leftDateFormat );
Assert.assertNotNull( tested.rightDateFormat );
Assert.assertEquals( CFG_DEFAULT_DATE_FORMAT , tested.rightDateFormat );
}
@Test
public void preprocessData() {
IsDateInRangePreprocessor tested = new IsDateInRangePreprocessor(); | // Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_CHECKED_DATE = "checked_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_DEFAULT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSXX";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_LEFT_DATE = "left_date";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RESULT_FIELD = "result_field";
//
// Path: src/main/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessor.java
// protected static final String CFG_RIGHT_DATE = "right_date";
//
// Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
// Path: src/test/java/org/jboss/elasticsearch/tools/content/IsDateInRangePreprocessorTest.java
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_CHECKED_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_DEFAULT_DATE_FORMAT;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_LEFT_DATE;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RESULT_FIELD;
import static org.jboss.elasticsearch.tools.content.IsDateInRangePreprocessor.CFG_RIGHT_DATE;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.common.settings.SettingsException;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test;
}
@Test
public void init() {
// case - mandatory fields only filled in
IsDateInRangePreprocessor tested = new IsDateInRangePreprocessor();
Map<String, Object> settings = new HashMap<String, Object>();
settings.put( CFG_CHECKED_DATE, "tested_date" );
settings.put( CFG_RESULT_FIELD, "target" );
settings.put( CFG_LEFT_DATE, "left_date" );
tested.init( "Test mapper", null, settings );
Assert.assertEquals( "Test mapper", tested.getName() );
Assert.assertEquals( "tested_date", tested.checkedDateField );
Assert.assertEquals( "target" , tested.resultField );
Assert.assertEquals( "left_date" , tested.leftDateField );
Assert.assertNull( tested.rightDateField );
Assert.assertNull( tested.sourceBases );
// Checking if default date format is used if not provided
Assert.assertNotNull( tested.leftDateFormat );
Assert.assertEquals( CFG_DEFAULT_DATE_FORMAT , tested.leftDateFormat );
Assert.assertNotNull( tested.rightDateFormat );
Assert.assertEquals( CFG_DEFAULT_DATE_FORMAT , tested.rightDateFormat );
}
@Test
public void preprocessData() {
IsDateInRangePreprocessor tested = new IsDateInRangePreprocessor(); | Map<String,Object> settings = TestUtils.loadJSONFromClasspathFile("/IsDateInRangePreprocessor_preprocessData.json"); |
searchisko/structured-content-tools | src/test/java/org/jboss/elasticsearch/tools/content/SimpleValueMapMapperPreprocessorTest.java | // Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
| import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test;
import org.mockito.Mockito; | tested.init("Test mapper", client, settings);
Assert.assertEquals("Test mapper", tested.getName());
Assert.assertEquals(client, tested.client);
Assert.assertEquals("source", tested.fieldSource);
Assert.assertEquals("target", tested.fieldTarget);
Assert.assertNull(tested.defaultValue);
Assert.assertNull(tested.valueMap);
// case - some default value and mapping here
settings.put(SimpleValueMapMapperPreprocessor.CFG_VALUE_DEFAULT, "Default");
Map<String, String> mapping = new HashMap<String, String>();
mapping.put("orig", "new");
settings.put(SimpleValueMapMapperPreprocessor.CFG_VALUE_MAPPING, mapping);
tested.init("Test mapper", client, settings);
Assert.assertEquals("Test mapper", tested.getName());
Assert.assertEquals(client, tested.client);
Assert.assertEquals("source", tested.fieldSource);
Assert.assertEquals("target", tested.fieldTarget);
Assert.assertEquals("Default", tested.defaultValue);
Assert.assertNotNull(tested.valueMap);
Assert.assertEquals(1, tested.valueMap.size());
}
@SuppressWarnings("unchecked")
@Test
public void preprocessData() {
Client client = Mockito.mock(Client.class);
SimpleValueMapMapperPreprocessor tested = new SimpleValueMapMapperPreprocessor();
tested | // Path: src/test/java/org/jboss/elasticsearch/tools/content/testtools/TestUtils.java
// public abstract class TestUtils {
//
// /**
// * Assert passed string is same as contnt of given file loaded from classpath.
// *
// * @param expectedFilePath path to file inside classpath
// * @param actual content to assert
// * @throws IOException
// */
// public static void assertStringFromClasspathFile(String expectedFilePath, String actual) throws IOException {
// Assert.assertEquals(readStringFromClasspathFile(expectedFilePath), actual);
// }
//
// /**
// * Read file from classpath into String. UTF-8 encoding expected.
// *
// * @param filePath in classpath to read data from.
// * @return file content.
// * @throws IOException
// */
// public static String readStringFromClasspathFile(String filePath) throws IOException {
// StringWriter stringWriter = new StringWriter();
// IOUtils.copy(TestUtils.class.getResourceAsStream(filePath), stringWriter, "UTF-8");
// return stringWriter.toString();
// }
//
// /**
// * Read JSON file from classpath into Map of Map structure.
// *
// * @param filePath path in classpath pointing to JSON file to read
// * @return parsed JSON file
// * @throws SettingsException
// */
// public static Map<String, Object> loadJSONFromClasspathFile(String filePath) throws SettingsException {
// XContentParser parser = null;
// try {
// parser = XContentFactory.xContent(XContentType.JSON).createParser(TestUtils.class.getResourceAsStream(filePath));
// return parser.mapAndClose();
// } catch (IOException e) {
// throw new SettingsException(e.getMessage(), e);
// } finally {
// if (parser != null)
// parser.close();
// }
// }
//
// }
// Path: src/test/java/org/jboss/elasticsearch/tools/content/SimpleValueMapMapperPreprocessorTest.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import junit.framework.Assert;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.jboss.elasticsearch.tools.content.testtools.TestUtils;
import org.junit.Test;
import org.mockito.Mockito;
tested.init("Test mapper", client, settings);
Assert.assertEquals("Test mapper", tested.getName());
Assert.assertEquals(client, tested.client);
Assert.assertEquals("source", tested.fieldSource);
Assert.assertEquals("target", tested.fieldTarget);
Assert.assertNull(tested.defaultValue);
Assert.assertNull(tested.valueMap);
// case - some default value and mapping here
settings.put(SimpleValueMapMapperPreprocessor.CFG_VALUE_DEFAULT, "Default");
Map<String, String> mapping = new HashMap<String, String>();
mapping.put("orig", "new");
settings.put(SimpleValueMapMapperPreprocessor.CFG_VALUE_MAPPING, mapping);
tested.init("Test mapper", client, settings);
Assert.assertEquals("Test mapper", tested.getName());
Assert.assertEquals(client, tested.client);
Assert.assertEquals("source", tested.fieldSource);
Assert.assertEquals("target", tested.fieldTarget);
Assert.assertEquals("Default", tested.defaultValue);
Assert.assertNotNull(tested.valueMap);
Assert.assertEquals(1, tested.valueMap.size());
}
@SuppressWarnings("unchecked")
@Test
public void preprocessData() {
Client client = Mockito.mock(Client.class);
SimpleValueMapMapperPreprocessor tested = new SimpleValueMapMapperPreprocessor();
tested | .init("Test mapper", client, TestUtils.loadJSONFromClasspathFile("/SimpleValueMapMapper_preprocessData.json")); |
khasang/SmartForecast | Forecast/app/src/main/java/com/khasang/forecast/MyApplication.java | // Path: Forecast/app/src/main/java/com/khasang/forecast/utils/DrawUtils.java
// public class DrawUtils {
// private static Context appContext;
//
// private static DrawUtils ourInstance = new DrawUtils();
// private float widthDpx;
// private int widthPx;
//
// public static DrawUtils getInstance() {
// return ourInstance;
// }
//
// public void init(Context context) {
// appContext = context.getApplicationContext();
// Display display = ((WindowManager) appContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
// DisplayMetrics metrics = new DisplayMetrics();
// display.getMetrics(metrics);
// widthPx = metrics.widthPixels;
// widthDpx = widthPx / metrics.density;
// }
//
// private DrawUtils() {
//
// }
//
// public float getWidthDpx() {
// return widthDpx;
// }
//
// public int getWidthPx() {
// return widthPx;
// }
// }
//
// Path: Forecast/app/src/main/java/com/khasang/forecast/utils/LocaleUtils.java
// public class LocaleUtils {
//
// public static void updateResources(Context context, String language) {
// if (language != null) {
// Locale locale = new Locale(language);
// Locale.setDefault(locale);
// Resources resources = context.getResources();
// Configuration configuration = resources.getConfiguration();
// configuration.locale = locale;
// resources.updateConfiguration(configuration, resources.getDisplayMetrics());
// }
// }
// }
| import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.preference.PreferenceManager;
import com.crashlytics.android.core.CrashlyticsCore;
import com.facebook.stetho.Stetho;
import com.crashlytics.android.Crashlytics;
import com.khasang.forecast.utils.DrawUtils;
import com.khasang.forecast.utils.LocaleUtils;
import io.fabric.sdk.android.Fabric; | package com.khasang.forecast;
/**
* Created by aleksandrlihovidov on 15.12.15.
*/
public class MyApplication extends Application {
private static Context context;
public static Context getAppContext() {
return MyApplication.context;
}
@Override
public void onCreate() {
super.onCreate();
/** Проверяет, если Debug mode, то не отправляет отчеты об ошибках */
CrashlyticsCore core = new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build();
Fabric.with(this, new Crashlytics.Builder().core(core).build());
| // Path: Forecast/app/src/main/java/com/khasang/forecast/utils/DrawUtils.java
// public class DrawUtils {
// private static Context appContext;
//
// private static DrawUtils ourInstance = new DrawUtils();
// private float widthDpx;
// private int widthPx;
//
// public static DrawUtils getInstance() {
// return ourInstance;
// }
//
// public void init(Context context) {
// appContext = context.getApplicationContext();
// Display display = ((WindowManager) appContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
// DisplayMetrics metrics = new DisplayMetrics();
// display.getMetrics(metrics);
// widthPx = metrics.widthPixels;
// widthDpx = widthPx / metrics.density;
// }
//
// private DrawUtils() {
//
// }
//
// public float getWidthDpx() {
// return widthDpx;
// }
//
// public int getWidthPx() {
// return widthPx;
// }
// }
//
// Path: Forecast/app/src/main/java/com/khasang/forecast/utils/LocaleUtils.java
// public class LocaleUtils {
//
// public static void updateResources(Context context, String language) {
// if (language != null) {
// Locale locale = new Locale(language);
// Locale.setDefault(locale);
// Resources resources = context.getResources();
// Configuration configuration = resources.getConfiguration();
// configuration.locale = locale;
// resources.updateConfiguration(configuration, resources.getDisplayMetrics());
// }
// }
// }
// Path: Forecast/app/src/main/java/com/khasang/forecast/MyApplication.java
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.preference.PreferenceManager;
import com.crashlytics.android.core.CrashlyticsCore;
import com.facebook.stetho.Stetho;
import com.crashlytics.android.Crashlytics;
import com.khasang.forecast.utils.DrawUtils;
import com.khasang.forecast.utils.LocaleUtils;
import io.fabric.sdk.android.Fabric;
package com.khasang.forecast;
/**
* Created by aleksandrlihovidov on 15.12.15.
*/
public class MyApplication extends Application {
private static Context context;
public static Context getAppContext() {
return MyApplication.context;
}
@Override
public void onCreate() {
super.onCreate();
/** Проверяет, если Debug mode, то не отправляет отчеты об ошибках */
CrashlyticsCore core = new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build();
Fabric.with(this, new Crashlytics.Builder().core(core).build());
| DrawUtils.getInstance().init(this); |
khasang/SmartForecast | Forecast/app/src/main/java/com/khasang/forecast/MyApplication.java | // Path: Forecast/app/src/main/java/com/khasang/forecast/utils/DrawUtils.java
// public class DrawUtils {
// private static Context appContext;
//
// private static DrawUtils ourInstance = new DrawUtils();
// private float widthDpx;
// private int widthPx;
//
// public static DrawUtils getInstance() {
// return ourInstance;
// }
//
// public void init(Context context) {
// appContext = context.getApplicationContext();
// Display display = ((WindowManager) appContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
// DisplayMetrics metrics = new DisplayMetrics();
// display.getMetrics(metrics);
// widthPx = metrics.widthPixels;
// widthDpx = widthPx / metrics.density;
// }
//
// private DrawUtils() {
//
// }
//
// public float getWidthDpx() {
// return widthDpx;
// }
//
// public int getWidthPx() {
// return widthPx;
// }
// }
//
// Path: Forecast/app/src/main/java/com/khasang/forecast/utils/LocaleUtils.java
// public class LocaleUtils {
//
// public static void updateResources(Context context, String language) {
// if (language != null) {
// Locale locale = new Locale(language);
// Locale.setDefault(locale);
// Resources resources = context.getResources();
// Configuration configuration = resources.getConfiguration();
// configuration.locale = locale;
// resources.updateConfiguration(configuration, resources.getDisplayMetrics());
// }
// }
// }
| import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.preference.PreferenceManager;
import com.crashlytics.android.core.CrashlyticsCore;
import com.facebook.stetho.Stetho;
import com.crashlytics.android.Crashlytics;
import com.khasang.forecast.utils.DrawUtils;
import com.khasang.forecast.utils.LocaleUtils;
import io.fabric.sdk.android.Fabric; | package com.khasang.forecast;
/**
* Created by aleksandrlihovidov on 15.12.15.
*/
public class MyApplication extends Application {
private static Context context;
public static Context getAppContext() {
return MyApplication.context;
}
@Override
public void onCreate() {
super.onCreate();
/** Проверяет, если Debug mode, то не отправляет отчеты об ошибках */
CrashlyticsCore core = new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build();
Fabric.with(this, new Crashlytics.Builder().core(core).build());
DrawUtils.getInstance().init(this);
MyApplication.context = getApplicationContext();
Stetho.initializeWithDefaults(this);
//FirebaseCrash.report(new Exception("My first Android non-fatal error"));
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
String languageCode = sharedPreferences.getString(getString(R.string.pref_language_key), null); | // Path: Forecast/app/src/main/java/com/khasang/forecast/utils/DrawUtils.java
// public class DrawUtils {
// private static Context appContext;
//
// private static DrawUtils ourInstance = new DrawUtils();
// private float widthDpx;
// private int widthPx;
//
// public static DrawUtils getInstance() {
// return ourInstance;
// }
//
// public void init(Context context) {
// appContext = context.getApplicationContext();
// Display display = ((WindowManager) appContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
// DisplayMetrics metrics = new DisplayMetrics();
// display.getMetrics(metrics);
// widthPx = metrics.widthPixels;
// widthDpx = widthPx / metrics.density;
// }
//
// private DrawUtils() {
//
// }
//
// public float getWidthDpx() {
// return widthDpx;
// }
//
// public int getWidthPx() {
// return widthPx;
// }
// }
//
// Path: Forecast/app/src/main/java/com/khasang/forecast/utils/LocaleUtils.java
// public class LocaleUtils {
//
// public static void updateResources(Context context, String language) {
// if (language != null) {
// Locale locale = new Locale(language);
// Locale.setDefault(locale);
// Resources resources = context.getResources();
// Configuration configuration = resources.getConfiguration();
// configuration.locale = locale;
// resources.updateConfiguration(configuration, resources.getDisplayMetrics());
// }
// }
// }
// Path: Forecast/app/src/main/java/com/khasang/forecast/MyApplication.java
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.preference.PreferenceManager;
import com.crashlytics.android.core.CrashlyticsCore;
import com.facebook.stetho.Stetho;
import com.crashlytics.android.Crashlytics;
import com.khasang.forecast.utils.DrawUtils;
import com.khasang.forecast.utils.LocaleUtils;
import io.fabric.sdk.android.Fabric;
package com.khasang.forecast;
/**
* Created by aleksandrlihovidov on 15.12.15.
*/
public class MyApplication extends Application {
private static Context context;
public static Context getAppContext() {
return MyApplication.context;
}
@Override
public void onCreate() {
super.onCreate();
/** Проверяет, если Debug mode, то не отправляет отчеты об ошибках */
CrashlyticsCore core = new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build();
Fabric.with(this, new Crashlytics.Builder().core(core).build());
DrawUtils.getInstance().init(this);
MyApplication.context = getApplicationContext();
Stetho.initializeWithDefaults(this);
//FirebaseCrash.report(new Exception("My first Android non-fatal error"));
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
String languageCode = sharedPreferences.getString(getString(R.string.pref_language_key), null); | LocaleUtils.updateResources(this, languageCode); |
khasang/SmartForecast | Forecast/app/src/main/java/com/khasang/forecast/sqlite/SQLiteWork.java | // Path: Forecast/app/src/main/java/com/khasang/forecast/MyApplication.java
// public class MyApplication extends Application {
//
// private static Context context;
//
// public static Context getAppContext() {
// return MyApplication.context;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// /** Проверяет, если Debug mode, то не отправляет отчеты об ошибках */
// CrashlyticsCore core = new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build();
// Fabric.with(this, new Crashlytics.Builder().core(core).build());
//
// DrawUtils.getInstance().init(this);
// MyApplication.context = getApplicationContext();
// Stetho.initializeWithDefaults(this);
//
// //FirebaseCrash.report(new Exception("My first Android non-fatal error"));
//
// SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
// String languageCode = sharedPreferences.getString(getString(R.string.pref_language_key), null);
// LocaleUtils.updateResources(this, languageCode);
// }
// }
| import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.khasang.forecast.MyApplication;
import java.util.ArrayList;
import java.util.HashMap; | package com.khasang.forecast.sqlite;
/**
* Класс для работы с запросами БД.
*
* @author maxim.kulikov
*/
public class SQLiteWork {
private SQLiteOpen dbWork;
private final int CURRENT_DB_VERSION = 6;
private static volatile SQLiteWork instance;
private SQLiteWork() {
}
public static SQLiteWork getInstance() {
if (instance == null) {
synchronized (SQLiteWork.class) {
if (instance == null) {
instance = new SQLiteWork();
instance.init();
}
}
}
return instance;
}
public void init() { | // Path: Forecast/app/src/main/java/com/khasang/forecast/MyApplication.java
// public class MyApplication extends Application {
//
// private static Context context;
//
// public static Context getAppContext() {
// return MyApplication.context;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// /** Проверяет, если Debug mode, то не отправляет отчеты об ошибках */
// CrashlyticsCore core = new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build();
// Fabric.with(this, new Crashlytics.Builder().core(core).build());
//
// DrawUtils.getInstance().init(this);
// MyApplication.context = getApplicationContext();
// Stetho.initializeWithDefaults(this);
//
// //FirebaseCrash.report(new Exception("My first Android non-fatal error"));
//
// SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
// String languageCode = sharedPreferences.getString(getString(R.string.pref_language_key), null);
// LocaleUtils.updateResources(this, languageCode);
// }
// }
// Path: Forecast/app/src/main/java/com/khasang/forecast/sqlite/SQLiteWork.java
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.khasang.forecast.MyApplication;
import java.util.ArrayList;
import java.util.HashMap;
package com.khasang.forecast.sqlite;
/**
* Класс для работы с запросами БД.
*
* @author maxim.kulikov
*/
public class SQLiteWork {
private SQLiteOpen dbWork;
private final int CURRENT_DB_VERSION = 6;
private static volatile SQLiteWork instance;
private SQLiteWork() {
}
public static SQLiteWork getInstance() {
if (instance == null) {
synchronized (SQLiteWork.class) {
if (instance == null) {
instance = new SQLiteWork();
instance.init();
}
}
}
return instance;
}
public void init() { | dbWork = new SQLiteOpen(MyApplication.getAppContext(), "Forecast.db", CURRENT_DB_VERSION); |
khasang/SmartForecast | Forecast/app/src/main/java/com/khasang/forecast/interfaces/IMapDataReceiver.java | // Path: Forecast/app/src/main/java/com/khasang/forecast/exceptions/EmptyCurrentAddressException.java
// public class EmptyCurrentAddressException extends Exception {
// }
| import com.khasang.forecast.exceptions.EmptyCurrentAddressException; | package com.khasang.forecast.interfaces;
/**
* Created by novoselov on 16.03.2016.
*/
public interface IMapDataReceiver {
void setLocationNameFromMap(String name);
| // Path: Forecast/app/src/main/java/com/khasang/forecast/exceptions/EmptyCurrentAddressException.java
// public class EmptyCurrentAddressException extends Exception {
// }
// Path: Forecast/app/src/main/java/com/khasang/forecast/interfaces/IMapDataReceiver.java
import com.khasang.forecast.exceptions.EmptyCurrentAddressException;
package com.khasang.forecast.interfaces;
/**
* Created by novoselov on 16.03.2016.
*/
public interface IMapDataReceiver {
void setLocationNameFromMap(String name);
| String setLocationCoordinatesFromMap(double latitude, double longitude) throws EmptyCurrentAddressException; |
khasang/SmartForecast | Forecast/app/src/main/java/com/khasang/forecast/adapters/TeamAdapter.java | // Path: Forecast/app/src/main/java/com/khasang/forecast/models/Developer.java
// public class Developer {
//
// private int nameResId;
// private Image image;
// private int descriptionResId;
// private List<Link> links;
//
// public Developer(int nameResId, Image image, int descriptionResId) {
// this.nameResId = nameResId;
// this.image = image;
// this.descriptionResId = descriptionResId;
// this.links = new ArrayList<>();
// }
//
// public int getNameResId() {
// return nameResId;
// }
//
// public Image getImage() {
// return image;
// }
//
// public int getDescriptionResId() {
// return descriptionResId;
// }
//
// public List<Link> getLinks() {
// return links;
// }
//
// public void setLinks(List<Link> links) {
// this.links = links;
// }
//
// public void addLink(Link link) {
// this.links.add(link);
// }
// }
//
// Path: Forecast/app/src/main/java/com/khasang/forecast/models/Link.java
// public class Link {
//
// private String title;
// private String url;
//
// public Link(String title, String url) {
// this.title = title;
// this.url = url;
// }
//
// public String getTitle() {
// return title;
// }
//
// public void setTitle(String title) {
// this.title = title;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
// }
| import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.khasang.forecast.R;
import com.khasang.forecast.models.Developer;
import com.khasang.forecast.models.Link;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import java.util.List;
import de.hdodenhof.circleimageview.CircleImageView; | package com.khasang.forecast.adapters;
public class TeamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context context; | // Path: Forecast/app/src/main/java/com/khasang/forecast/models/Developer.java
// public class Developer {
//
// private int nameResId;
// private Image image;
// private int descriptionResId;
// private List<Link> links;
//
// public Developer(int nameResId, Image image, int descriptionResId) {
// this.nameResId = nameResId;
// this.image = image;
// this.descriptionResId = descriptionResId;
// this.links = new ArrayList<>();
// }
//
// public int getNameResId() {
// return nameResId;
// }
//
// public Image getImage() {
// return image;
// }
//
// public int getDescriptionResId() {
// return descriptionResId;
// }
//
// public List<Link> getLinks() {
// return links;
// }
//
// public void setLinks(List<Link> links) {
// this.links = links;
// }
//
// public void addLink(Link link) {
// this.links.add(link);
// }
// }
//
// Path: Forecast/app/src/main/java/com/khasang/forecast/models/Link.java
// public class Link {
//
// private String title;
// private String url;
//
// public Link(String title, String url) {
// this.title = title;
// this.url = url;
// }
//
// public String getTitle() {
// return title;
// }
//
// public void setTitle(String title) {
// this.title = title;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
// }
// Path: Forecast/app/src/main/java/com/khasang/forecast/adapters/TeamAdapter.java
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.khasang.forecast.R;
import com.khasang.forecast.models.Developer;
import com.khasang.forecast.models.Link;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import java.util.List;
import de.hdodenhof.circleimageview.CircleImageView;
package com.khasang.forecast.adapters;
public class TeamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context context; | private List<Developer> developers; |
khasang/SmartForecast | Forecast/app/src/main/java/com/khasang/forecast/adapters/TeamAdapter.java | // Path: Forecast/app/src/main/java/com/khasang/forecast/models/Developer.java
// public class Developer {
//
// private int nameResId;
// private Image image;
// private int descriptionResId;
// private List<Link> links;
//
// public Developer(int nameResId, Image image, int descriptionResId) {
// this.nameResId = nameResId;
// this.image = image;
// this.descriptionResId = descriptionResId;
// this.links = new ArrayList<>();
// }
//
// public int getNameResId() {
// return nameResId;
// }
//
// public Image getImage() {
// return image;
// }
//
// public int getDescriptionResId() {
// return descriptionResId;
// }
//
// public List<Link> getLinks() {
// return links;
// }
//
// public void setLinks(List<Link> links) {
// this.links = links;
// }
//
// public void addLink(Link link) {
// this.links.add(link);
// }
// }
//
// Path: Forecast/app/src/main/java/com/khasang/forecast/models/Link.java
// public class Link {
//
// private String title;
// private String url;
//
// public Link(String title, String url) {
// this.title = title;
// this.url = url;
// }
//
// public String getTitle() {
// return title;
// }
//
// public void setTitle(String title) {
// this.title = title;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
// }
| import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.khasang.forecast.R;
import com.khasang.forecast.models.Developer;
import com.khasang.forecast.models.Link;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import java.util.List;
import de.hdodenhof.circleimageview.CircleImageView; | .load(url)
.placeholder(R.drawable.ic_person)
.error(R.drawable.ic_person)
.resize(iconParams.width, iconParams.height)
.into(holder.iconView);
Picasso.with(context)
.load(wallpapers[position % wallpapers.length])
.resize(wallpaperWidth, wallpaperHeight)
.centerCrop()
.into(holder.wallpaper, new Callback() {
@Override
public void onSuccess() {
holder.nameView.setTextColor(ContextCompat.getColor(context, R.color.white));
holder.descriptionView.setTextColor(ContextCompat.getColor(context, R.color.white));
}
@Override
public void onError() {
holder.nameView.setTextColor(ContextCompat.getColor(context, R.color.grey));
holder.descriptionView.setTextColor(ContextCompat.getColor(context, R.color.grey));
}
});
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT);
params.weight = 1;
Typeface typeface = Typeface.create("sans-serif-regular", Typeface.BOLD);
int buttonPadding = context.getResources().getDimensionPixelSize(R.dimen.social_button_padding);
holder.links.removeAllViews(); | // Path: Forecast/app/src/main/java/com/khasang/forecast/models/Developer.java
// public class Developer {
//
// private int nameResId;
// private Image image;
// private int descriptionResId;
// private List<Link> links;
//
// public Developer(int nameResId, Image image, int descriptionResId) {
// this.nameResId = nameResId;
// this.image = image;
// this.descriptionResId = descriptionResId;
// this.links = new ArrayList<>();
// }
//
// public int getNameResId() {
// return nameResId;
// }
//
// public Image getImage() {
// return image;
// }
//
// public int getDescriptionResId() {
// return descriptionResId;
// }
//
// public List<Link> getLinks() {
// return links;
// }
//
// public void setLinks(List<Link> links) {
// this.links = links;
// }
//
// public void addLink(Link link) {
// this.links.add(link);
// }
// }
//
// Path: Forecast/app/src/main/java/com/khasang/forecast/models/Link.java
// public class Link {
//
// private String title;
// private String url;
//
// public Link(String title, String url) {
// this.title = title;
// this.url = url;
// }
//
// public String getTitle() {
// return title;
// }
//
// public void setTitle(String title) {
// this.title = title;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
// }
// Path: Forecast/app/src/main/java/com/khasang/forecast/adapters/TeamAdapter.java
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.khasang.forecast.R;
import com.khasang.forecast.models.Developer;
import com.khasang.forecast.models.Link;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import java.util.List;
import de.hdodenhof.circleimageview.CircleImageView;
.load(url)
.placeholder(R.drawable.ic_person)
.error(R.drawable.ic_person)
.resize(iconParams.width, iconParams.height)
.into(holder.iconView);
Picasso.with(context)
.load(wallpapers[position % wallpapers.length])
.resize(wallpaperWidth, wallpaperHeight)
.centerCrop()
.into(holder.wallpaper, new Callback() {
@Override
public void onSuccess() {
holder.nameView.setTextColor(ContextCompat.getColor(context, R.color.white));
holder.descriptionView.setTextColor(ContextCompat.getColor(context, R.color.white));
}
@Override
public void onError() {
holder.nameView.setTextColor(ContextCompat.getColor(context, R.color.grey));
holder.descriptionView.setTextColor(ContextCompat.getColor(context, R.color.grey));
}
});
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT);
params.weight = 1;
Typeface typeface = Typeface.create("sans-serif-regular", Typeface.BOLD);
int buttonPadding = context.getResources().getDimensionPixelSize(R.dimen.social_button_padding);
holder.links.removeAllViews(); | List<Link> links = developer.getLinks(); |
khasang/SmartForecast | Forecast/app/src/main/java/com/khasang/forecast/stations/WeatherStationFactory.java | // Path: Forecast/app/src/main/java/com/khasang/forecast/MyApplication.java
// public class MyApplication extends Application {
//
// private static Context context;
//
// public static Context getAppContext() {
// return MyApplication.context;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// /** Проверяет, если Debug mode, то не отправляет отчеты об ошибках */
// CrashlyticsCore core = new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build();
// Fabric.with(this, new Crashlytics.Builder().core(core).build());
//
// DrawUtils.getInstance().init(this);
// MyApplication.context = getApplicationContext();
// Stetho.initializeWithDefaults(this);
//
// //FirebaseCrash.report(new Exception("My first Android non-fatal error"));
//
// SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
// String languageCode = sharedPreferences.getString(getString(R.string.pref_language_key), null);
// LocaleUtils.updateResources(this, languageCode);
// }
// }
| import com.khasang.forecast.MyApplication;
import com.khasang.forecast.R;
import java.util.HashMap; | package com.khasang.forecast.stations;
/**
* Created by Роман on 26.11.2015.
*/
public class WeatherStationFactory {
private HashMap<ServiceType, WeatherStation> stations;
public WeatherStationFactory() {
stations = new HashMap<>();
}
public WeatherStationFactory addOpenWeatherMap() {
WeatherStation ws = new OpenWeatherMap();
ws.serviceType = ServiceType.OPEN_WEATHER_MAP;
stations.put(ServiceType.OPEN_WEATHER_MAP, ws);
return this;
}
public HashMap<ServiceType, WeatherStation> create() {
return stations;
}
/* TODO
При добадении новых сервисов добавить в билдер строитель для каждого сервиса по типу
public Builder addOpenWeatherMap
*/
public enum ServiceType {
OPEN_WEATHER_MAP {
@Override
public String toString() { | // Path: Forecast/app/src/main/java/com/khasang/forecast/MyApplication.java
// public class MyApplication extends Application {
//
// private static Context context;
//
// public static Context getAppContext() {
// return MyApplication.context;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// /** Проверяет, если Debug mode, то не отправляет отчеты об ошибках */
// CrashlyticsCore core = new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build();
// Fabric.with(this, new Crashlytics.Builder().core(core).build());
//
// DrawUtils.getInstance().init(this);
// MyApplication.context = getApplicationContext();
// Stetho.initializeWithDefaults(this);
//
// //FirebaseCrash.report(new Exception("My first Android non-fatal error"));
//
// SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
// String languageCode = sharedPreferences.getString(getString(R.string.pref_language_key), null);
// LocaleUtils.updateResources(this, languageCode);
// }
// }
// Path: Forecast/app/src/main/java/com/khasang/forecast/stations/WeatherStationFactory.java
import com.khasang.forecast.MyApplication;
import com.khasang.forecast.R;
import java.util.HashMap;
package com.khasang.forecast.stations;
/**
* Created by Роман on 26.11.2015.
*/
public class WeatherStationFactory {
private HashMap<ServiceType, WeatherStation> stations;
public WeatherStationFactory() {
stations = new HashMap<>();
}
public WeatherStationFactory addOpenWeatherMap() {
WeatherStation ws = new OpenWeatherMap();
ws.serviceType = ServiceType.OPEN_WEATHER_MAP;
stations.put(ServiceType.OPEN_WEATHER_MAP, ws);
return this;
}
public HashMap<ServiceType, WeatherStation> create() {
return stations;
}
/* TODO
При добадении новых сервисов добавить в билдер строитель для каждого сервиса по типу
public Builder addOpenWeatherMap
*/
public enum ServiceType {
OPEN_WEATHER_MAP {
@Override
public String toString() { | return MyApplication.getAppContext().getString(R.string.service_name_open_weather_map); |
khasang/SmartForecast | Forecast/app/src/main/java/com/khasang/forecast/stations/WeatherStation.java | // Path: Forecast/app/src/main/java/com/khasang/forecast/position/Coordinate.java
// public class Coordinate implements Comparable<Coordinate> {
// private double latitude;
// private double longitude;
//
// public Coordinate(double latitude, double longitude) {
// this.latitude = latitude;
// this.longitude = longitude;
// }
//
// public Coordinate() {
//
// }
//
// public double getLatitude() {
// return latitude;
// }
//
// public void setLatitude(double latitude) {
// this.latitude = latitude;
// }
//
// public double getLongitude() {
// return longitude;
// }
//
// public void setLongitude(double longitude) {
// this.longitude = longitude;
// }
//
// @Override
// public int compareTo(Coordinate another) {
// if (another == null) {
// return 1;
// }
// if (latitude == another.getLatitude() && longitude == another.getLongitude()) {
// return 0;
// }
// return 1;
// }
//
// @Override
// public String toString() {
// return "Coordinate{latitude=" + latitude + ", longitude=" + longitude + "}";
// }
//
// public String convertToTimezoneUrlParameterString() {
// return String.valueOf(latitude) + "," + String.valueOf(longitude);
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// Coordinate that = (Coordinate) o;
//
// if (Double.compare(that.latitude, latitude) != 0) return false;
// return Double.compare(that.longitude, longitude) == 0;
//
// }
//
// @Override
// public int hashCode() {
// int result;
// long temp;
// temp = Double.doubleToLongBits(latitude);
// result = (int) (temp ^ (temp >>> 32));
// temp = Double.doubleToLongBits(longitude);
// result = 31 * result + (int) (temp ^ (temp >>> 32));
// return result;
// }
// }
| import com.khasang.forecast.position.Coordinate;
import java.util.LinkedList; | package com.khasang.forecast.stations;
/**
* Created by novoselov on 24.11.2015.
*/
public abstract class WeatherStation {
public enum ResponseType {CURRENT, HOURLY, DAILY};
WeatherStationFactory.ServiceType serviceType;
public WeatherStationFactory.ServiceType getServiceType() {
return serviceType;
}
public String getWeatherStationName() {
return serviceType.toString();
}
| // Path: Forecast/app/src/main/java/com/khasang/forecast/position/Coordinate.java
// public class Coordinate implements Comparable<Coordinate> {
// private double latitude;
// private double longitude;
//
// public Coordinate(double latitude, double longitude) {
// this.latitude = latitude;
// this.longitude = longitude;
// }
//
// public Coordinate() {
//
// }
//
// public double getLatitude() {
// return latitude;
// }
//
// public void setLatitude(double latitude) {
// this.latitude = latitude;
// }
//
// public double getLongitude() {
// return longitude;
// }
//
// public void setLongitude(double longitude) {
// this.longitude = longitude;
// }
//
// @Override
// public int compareTo(Coordinate another) {
// if (another == null) {
// return 1;
// }
// if (latitude == another.getLatitude() && longitude == another.getLongitude()) {
// return 0;
// }
// return 1;
// }
//
// @Override
// public String toString() {
// return "Coordinate{latitude=" + latitude + ", longitude=" + longitude + "}";
// }
//
// public String convertToTimezoneUrlParameterString() {
// return String.valueOf(latitude) + "," + String.valueOf(longitude);
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// Coordinate that = (Coordinate) o;
//
// if (Double.compare(that.latitude, latitude) != 0) return false;
// return Double.compare(that.longitude, longitude) == 0;
//
// }
//
// @Override
// public int hashCode() {
// int result;
// long temp;
// temp = Double.doubleToLongBits(latitude);
// result = (int) (temp ^ (temp >>> 32));
// temp = Double.doubleToLongBits(longitude);
// result = 31 * result + (int) (temp ^ (temp >>> 32));
// return result;
// }
// }
// Path: Forecast/app/src/main/java/com/khasang/forecast/stations/WeatherStation.java
import com.khasang.forecast.position.Coordinate;
import java.util.LinkedList;
package com.khasang.forecast.stations;
/**
* Created by novoselov on 24.11.2015.
*/
public abstract class WeatherStation {
public enum ResponseType {CURRENT, HOURLY, DAILY};
WeatherStationFactory.ServiceType serviceType;
public WeatherStationFactory.ServiceType getServiceType() {
return serviceType;
}
public String getWeatherStationName() {
return serviceType.toString();
}
| public abstract void updateWeather(LinkedList<ResponseType> requestQueue, int cityID, Coordinate coordinate); |
khasang/SmartForecast | Forecast/app/src/main/java/com/khasang/forecast/stations/OpenWeatherMapService.java | // Path: Forecast/app/src/main/java/com/khasang/forecast/models/DailyResponse.java
// public class DailyResponse {
//
// private City city;
// private String cod;
// private Double message;
// private Integer cnt;
// private List<DailyForecastList> list = new ArrayList<>();
//
// public City getCity() {
// return city;
// }
//
// public String getCod() {
// return cod;
// }
//
// public Double getMessage() {
// return message;
// }
//
// public Integer getCnt() {
// return cnt;
// }
//
// public List<DailyForecastList> getList() {
// return list;
// }
//
// @Override
// public String toString() {
// return "DailyResponse{" +
// "city=" + city +
// ", cod='" + cod + '\'' +
// ", message=" + message +
// ", cnt=" + cnt +
// ", list=" + list +
// '}';
// }
// }
//
// Path: Forecast/app/src/main/java/com/khasang/forecast/models/OpenWeatherMapResponse.java
// public class OpenWeatherMapResponse {
// private ArrayList<Weather> weather = new ArrayList<>();
// private Main main;
// private Wind wind;
// private Clouds clouds;
// private Rain rain;
// private long dt;
// private Sys sys;
// private long id;
// private String name;
// private List<HourlyForecastList> list = new ArrayList<>();
//
// public ArrayList<Weather> getWeather() {
// return weather;
// }
//
// public Main getMain() {
// return main;
// }
//
// public Wind getWind() {
// return wind;
// }
//
// public Clouds getClouds() {
// return clouds;
// }
//
// public Rain getRain() {
// return rain;
// }
//
// public long getDt() {
// return dt;
// }
//
// public Sys getSys() {
// return sys;
// }
//
// public long getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public List<HourlyForecastList> getList() {
// return list;
// }
//
// @Override
// public String toString() {
// return "OpenWeatherMapResponse{" +
// "weather=" + weather +
// ", main=" + main +
// ", wind=" + wind +
// ", clouds=" + clouds +
// ", rain=" + rain +
// ", dt=" + dt +
// ", sys=" + sys +
// ", id=" + id +
// ", name='" + name + '\'' +
// ", list=" + list +
// '}';
// }
// }
| import com.khasang.forecast.models.DailyResponse;
import com.khasang.forecast.models.OpenWeatherMapResponse;
import retrofit.Call;
import retrofit.http.GET;
import retrofit.http.Query; | package com.khasang.forecast.stations;
/**
* Этот интерфейс задает конечные точки для запроса к API. Методы и параметры запроса указываются
* через аннотации.
* <p/>
* <p><b>Методы:</b>
* <ul>
* <li>{@link #getCurrent(double, double)}</li>
* <li>{@link #getCurrent(String)}</li>
* <li>{@link #getHourly(double, double, int)}</li>
* <li>{@link #getHourly(String, int)}</li>
* <li>{@link #getDaily(double, double, int)}</li>
* <li>{@link #getDaily(String, int)}</li>
* </ul>
*/
public interface OpenWeatherMapService {
/**
* Получить текущий прогноз погоды по заданным географическим координатам.
*
* @param latitude географическая широта.
* @param longitude географическая долгота.
*/
@GET("/data/2.5/weather") | // Path: Forecast/app/src/main/java/com/khasang/forecast/models/DailyResponse.java
// public class DailyResponse {
//
// private City city;
// private String cod;
// private Double message;
// private Integer cnt;
// private List<DailyForecastList> list = new ArrayList<>();
//
// public City getCity() {
// return city;
// }
//
// public String getCod() {
// return cod;
// }
//
// public Double getMessage() {
// return message;
// }
//
// public Integer getCnt() {
// return cnt;
// }
//
// public List<DailyForecastList> getList() {
// return list;
// }
//
// @Override
// public String toString() {
// return "DailyResponse{" +
// "city=" + city +
// ", cod='" + cod + '\'' +
// ", message=" + message +
// ", cnt=" + cnt +
// ", list=" + list +
// '}';
// }
// }
//
// Path: Forecast/app/src/main/java/com/khasang/forecast/models/OpenWeatherMapResponse.java
// public class OpenWeatherMapResponse {
// private ArrayList<Weather> weather = new ArrayList<>();
// private Main main;
// private Wind wind;
// private Clouds clouds;
// private Rain rain;
// private long dt;
// private Sys sys;
// private long id;
// private String name;
// private List<HourlyForecastList> list = new ArrayList<>();
//
// public ArrayList<Weather> getWeather() {
// return weather;
// }
//
// public Main getMain() {
// return main;
// }
//
// public Wind getWind() {
// return wind;
// }
//
// public Clouds getClouds() {
// return clouds;
// }
//
// public Rain getRain() {
// return rain;
// }
//
// public long getDt() {
// return dt;
// }
//
// public Sys getSys() {
// return sys;
// }
//
// public long getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public List<HourlyForecastList> getList() {
// return list;
// }
//
// @Override
// public String toString() {
// return "OpenWeatherMapResponse{" +
// "weather=" + weather +
// ", main=" + main +
// ", wind=" + wind +
// ", clouds=" + clouds +
// ", rain=" + rain +
// ", dt=" + dt +
// ", sys=" + sys +
// ", id=" + id +
// ", name='" + name + '\'' +
// ", list=" + list +
// '}';
// }
// }
// Path: Forecast/app/src/main/java/com/khasang/forecast/stations/OpenWeatherMapService.java
import com.khasang.forecast.models.DailyResponse;
import com.khasang.forecast.models.OpenWeatherMapResponse;
import retrofit.Call;
import retrofit.http.GET;
import retrofit.http.Query;
package com.khasang.forecast.stations;
/**
* Этот интерфейс задает конечные точки для запроса к API. Методы и параметры запроса указываются
* через аннотации.
* <p/>
* <p><b>Методы:</b>
* <ul>
* <li>{@link #getCurrent(double, double)}</li>
* <li>{@link #getCurrent(String)}</li>
* <li>{@link #getHourly(double, double, int)}</li>
* <li>{@link #getHourly(String, int)}</li>
* <li>{@link #getDaily(double, double, int)}</li>
* <li>{@link #getDaily(String, int)}</li>
* </ul>
*/
public interface OpenWeatherMapService {
/**
* Получить текущий прогноз погоды по заданным географическим координатам.
*
* @param latitude географическая широта.
* @param longitude географическая долгота.
*/
@GET("/data/2.5/weather") | Call<OpenWeatherMapResponse> getCurrent(@Query("lat") double latitude, @Query("lon") double longitude); |
khasang/SmartForecast | Forecast/app/src/main/java/com/khasang/forecast/location/LocationParser.java | // Path: Forecast/app/src/main/java/com/khasang/forecast/exceptions/EmptyCurrentAddressException.java
// public class EmptyCurrentAddressException extends Exception {
// }
//
// Path: Forecast/app/src/main/java/com/khasang/forecast/exceptions/NoAvailableAddressesException.java
// public class NoAvailableAddressesException extends Exception {
// }
| import android.location.Address;
import com.khasang.forecast.exceptions.EmptyCurrentAddressException;
import com.khasang.forecast.exceptions.NoAvailableAddressesException;
import java.util.List; | package com.khasang.forecast.location;
/**
* Created by roman on 03.02.16.
*/
public class LocationParser { // кидать ошибку если нехватает элементов
List<Address> list;
String country;
String region;
String subRegion;
String city;
public LocationParser() {
this(null);
}
public LocationParser(List<Address> list) {
this.list = list;
country = null;
region = null;
subRegion = null;
city = null;
}
public LocationParser setAddressesList(List<Address> list) {
this.list = list;
return this;
}
| // Path: Forecast/app/src/main/java/com/khasang/forecast/exceptions/EmptyCurrentAddressException.java
// public class EmptyCurrentAddressException extends Exception {
// }
//
// Path: Forecast/app/src/main/java/com/khasang/forecast/exceptions/NoAvailableAddressesException.java
// public class NoAvailableAddressesException extends Exception {
// }
// Path: Forecast/app/src/main/java/com/khasang/forecast/location/LocationParser.java
import android.location.Address;
import com.khasang.forecast.exceptions.EmptyCurrentAddressException;
import com.khasang.forecast.exceptions.NoAvailableAddressesException;
import java.util.List;
package com.khasang.forecast.location;
/**
* Created by roman on 03.02.16.
*/
public class LocationParser { // кидать ошибку если нехватает элементов
List<Address> list;
String country;
String region;
String subRegion;
String city;
public LocationParser() {
this(null);
}
public LocationParser(List<Address> list) {
this.list = list;
country = null;
region = null;
subRegion = null;
city = null;
}
public LocationParser setAddressesList(List<Address> list) {
this.list = list;
return this;
}
| public LocationParser parseList() throws NoAvailableAddressesException { |
khasang/SmartForecast | Forecast/app/src/main/java/com/khasang/forecast/location/LocationParser.java | // Path: Forecast/app/src/main/java/com/khasang/forecast/exceptions/EmptyCurrentAddressException.java
// public class EmptyCurrentAddressException extends Exception {
// }
//
// Path: Forecast/app/src/main/java/com/khasang/forecast/exceptions/NoAvailableAddressesException.java
// public class NoAvailableAddressesException extends Exception {
// }
| import android.location.Address;
import com.khasang.forecast.exceptions.EmptyCurrentAddressException;
import com.khasang.forecast.exceptions.NoAvailableAddressesException;
import java.util.List; | city = null;
}
public LocationParser setAddressesList(List<Address> list) {
this.list = list;
return this;
}
public LocationParser parseList() throws NoAvailableAddressesException {
if (list == null || list.size() == 0) {
throw new NoAvailableAddressesException();
} else {
for (Address address : list) {
if (country == null) {
country = address.getCountryName();
}
if (region == null) {
region = address.getAdminArea();
}
if (subRegion == null) {
subRegion = address.getSubAdminArea();
}
if (city == null) {
city = address.getLocality();
}
}
}
return this;
}
| // Path: Forecast/app/src/main/java/com/khasang/forecast/exceptions/EmptyCurrentAddressException.java
// public class EmptyCurrentAddressException extends Exception {
// }
//
// Path: Forecast/app/src/main/java/com/khasang/forecast/exceptions/NoAvailableAddressesException.java
// public class NoAvailableAddressesException extends Exception {
// }
// Path: Forecast/app/src/main/java/com/khasang/forecast/location/LocationParser.java
import android.location.Address;
import com.khasang.forecast.exceptions.EmptyCurrentAddressException;
import com.khasang.forecast.exceptions.NoAvailableAddressesException;
import java.util.List;
city = null;
}
public LocationParser setAddressesList(List<Address> list) {
this.list = list;
return this;
}
public LocationParser parseList() throws NoAvailableAddressesException {
if (list == null || list.size() == 0) {
throw new NoAvailableAddressesException();
} else {
for (Address address : list) {
if (country == null) {
country = address.getCountryName();
}
if (region == null) {
region = address.getAdminArea();
}
if (subRegion == null) {
subRegion = address.getSubAdminArea();
}
if (city == null) {
city = address.getLocality();
}
}
}
return this;
}
| public String getAddressLine() throws EmptyCurrentAddressException { |
khasang/SmartForecast | Forecast/app/src/main/java/com/khasang/forecast/position/Wind.java | // Path: Forecast/app/src/main/java/com/khasang/forecast/MyApplication.java
// public class MyApplication extends Application {
//
// private static Context context;
//
// public static Context getAppContext() {
// return MyApplication.context;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// /** Проверяет, если Debug mode, то не отправляет отчеты об ошибках */
// CrashlyticsCore core = new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build();
// Fabric.with(this, new Crashlytics.Builder().core(core).build());
//
// DrawUtils.getInstance().init(this);
// MyApplication.context = getApplicationContext();
// Stetho.initializeWithDefaults(this);
//
// //FirebaseCrash.report(new Exception("My first Android non-fatal error"));
//
// SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
// String languageCode = sharedPreferences.getString(getString(R.string.pref_language_key), null);
// LocaleUtils.updateResources(this, languageCode);
// }
// }
| import com.khasang.forecast.MyApplication;
import com.khasang.forecast.R; | package com.khasang.forecast.position;
/**
* Created by Veda on 24.11.15.
*/
public class Wind {
private Direction direction;
private double speed;
public static enum Direction { | // Path: Forecast/app/src/main/java/com/khasang/forecast/MyApplication.java
// public class MyApplication extends Application {
//
// private static Context context;
//
// public static Context getAppContext() {
// return MyApplication.context;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// /** Проверяет, если Debug mode, то не отправляет отчеты об ошибках */
// CrashlyticsCore core = new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build();
// Fabric.with(this, new Crashlytics.Builder().core(core).build());
//
// DrawUtils.getInstance().init(this);
// MyApplication.context = getApplicationContext();
// Stetho.initializeWithDefaults(this);
//
// //FirebaseCrash.report(new Exception("My first Android non-fatal error"));
//
// SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
// String languageCode = sharedPreferences.getString(getString(R.string.pref_language_key), null);
// LocaleUtils.updateResources(this, languageCode);
// }
// }
// Path: Forecast/app/src/main/java/com/khasang/forecast/position/Wind.java
import com.khasang.forecast.MyApplication;
import com.khasang.forecast.R;
package com.khasang.forecast.position;
/**
* Created by Veda on 24.11.15.
*/
public class Wind {
private Direction direction;
private double speed;
public static enum Direction { | NORTH(MyApplication.getAppContext().getString(R.string.N)), |
khasang/SmartForecast | Forecast/app/src/main/java/com/khasang/forecast/adapters/ChangelogAdapter.java | // Path: Forecast/app/src/main/java/com/khasang/forecast/models/Changelog.java
// public class Changelog {
//
// private int versionResId;
// private Date date;
// private Image image;
// private int changesResId;
//
// public int getVersionResId() {
// return versionResId;
// }
//
// public void setVersionResId(int versionResId) {
// this.versionResId = versionResId;
// }
//
// public Date getDate() {
// return date;
// }
//
// public void setDate(Date date) {
// this.date = date;
// }
//
// public Image getImage() {
// return image;
// }
//
// public void setImage(Image image) {
// this.image = image;
// }
//
// public int getChangesResId() {
// return changesResId;
// }
//
// public void setChangesResId(int changesResId) {
// this.changesResId = changesResId;
// }
// }
| import android.content.Context;
import android.os.Build;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.khasang.forecast.R;
import com.khasang.forecast.models.Changelog;
import com.khasang.forecast.models.Image;
import com.squareup.picasso.Picasso;
import java.text.DateFormat;
import java.util.List; | package com.khasang.forecast.adapters;
public class ChangelogAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context context; | // Path: Forecast/app/src/main/java/com/khasang/forecast/models/Changelog.java
// public class Changelog {
//
// private int versionResId;
// private Date date;
// private Image image;
// private int changesResId;
//
// public int getVersionResId() {
// return versionResId;
// }
//
// public void setVersionResId(int versionResId) {
// this.versionResId = versionResId;
// }
//
// public Date getDate() {
// return date;
// }
//
// public void setDate(Date date) {
// this.date = date;
// }
//
// public Image getImage() {
// return image;
// }
//
// public void setImage(Image image) {
// this.image = image;
// }
//
// public int getChangesResId() {
// return changesResId;
// }
//
// public void setChangesResId(int changesResId) {
// this.changesResId = changesResId;
// }
// }
// Path: Forecast/app/src/main/java/com/khasang/forecast/adapters/ChangelogAdapter.java
import android.content.Context;
import android.os.Build;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.khasang.forecast.R;
import com.khasang.forecast.models.Changelog;
import com.khasang.forecast.models.Image;
import com.squareup.picasso.Picasso;
import java.text.DateFormat;
import java.util.List;
package com.khasang.forecast.adapters;
public class ChangelogAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context context; | private List<Changelog> changelogs; |
wmaop/wm-aop | src/main/java/org/wmaop/aop/stub/StubLifecycleObserver.java | // Path: src/main/java/org/wmaop/aop/advice/Advice.java
// public class Advice {
//
// private final PointCut pointCut;
// private final Interceptor interceptor;
// private final String id;
// private AdviceState adviceState = AdviceState.NEW;
// private final Remit remit;
//
// public Advice(String id, Remit remit, PointCut pointCut, Interceptor interceptor) {
// this.pointCut = pointCut;
// this.interceptor = interceptor;
// this.id = id;
// this.remit = remit;
// }
//
// public Remit getRemit() {
// return remit;
// }
//
// public PointCut getPointCut() {
// return pointCut;
// }
//
// public boolean isApplicable(FlowPosition pipelinePosition, IData idata){
// return pointCut.isApplicable(pipelinePosition, idata) && remit.isApplicable();
// }
//
// public Interceptor getInterceptor() {
// return interceptor;
// }
//
// public String getId() {
// return id;
// }
//
// public AdviceState getAdviceState() {
// return adviceState;
// }
//
// public void setAdviceState(AdviceState adviceState) {
// this.adviceState = adviceState;
// }
//
// @Override
// public String toString() {
// return id + ' ' + adviceState + ' ' + pointCut + ' ' + interceptor + ' ' + pointCut.getInterceptPoint() + ' ' + remit;
// }
//
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("state", adviceState.toString());
// am.put("adviceId", id);
// am.put("pointcut", pointCut.toMap());
// am.put("interceptor", interceptor.toMap());
// am.put("remit", remit.toString());
// return am;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Advice other = (Advice) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
// }
| import java.util.Observable;
import java.util.Observer;
import org.wmaop.aop.advice.Advice;
| package org.wmaop.aop.stub;
public class StubLifecycleObserver implements Observer {
private StubManager stubManager;
public StubLifecycleObserver(StubManager stubManager) {
this.stubManager = stubManager;
}
@Override
public void update(Observable o, Object arg) {
| // Path: src/main/java/org/wmaop/aop/advice/Advice.java
// public class Advice {
//
// private final PointCut pointCut;
// private final Interceptor interceptor;
// private final String id;
// private AdviceState adviceState = AdviceState.NEW;
// private final Remit remit;
//
// public Advice(String id, Remit remit, PointCut pointCut, Interceptor interceptor) {
// this.pointCut = pointCut;
// this.interceptor = interceptor;
// this.id = id;
// this.remit = remit;
// }
//
// public Remit getRemit() {
// return remit;
// }
//
// public PointCut getPointCut() {
// return pointCut;
// }
//
// public boolean isApplicable(FlowPosition pipelinePosition, IData idata){
// return pointCut.isApplicable(pipelinePosition, idata) && remit.isApplicable();
// }
//
// public Interceptor getInterceptor() {
// return interceptor;
// }
//
// public String getId() {
// return id;
// }
//
// public AdviceState getAdviceState() {
// return adviceState;
// }
//
// public void setAdviceState(AdviceState adviceState) {
// this.adviceState = adviceState;
// }
//
// @Override
// public String toString() {
// return id + ' ' + adviceState + ' ' + pointCut + ' ' + interceptor + ' ' + pointCut.getInterceptPoint() + ' ' + remit;
// }
//
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("state", adviceState.toString());
// am.put("adviceId", id);
// am.put("pointcut", pointCut.toMap());
// am.put("interceptor", interceptor.toMap());
// am.put("remit", remit.toString());
// return am;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Advice other = (Advice) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
// }
// Path: src/main/java/org/wmaop/aop/stub/StubLifecycleObserver.java
import java.util.Observable;
import java.util.Observer;
import org.wmaop.aop.advice.Advice;
package org.wmaop.aop.stub;
public class StubLifecycleObserver implements Observer {
private StubManager stubManager;
public StubLifecycleObserver(StubManager stubManager) {
this.stubManager = stubManager;
}
@Override
public void update(Observable o, Object arg) {
| Advice advice = (Advice)arg;
|
wmaop/wm-aop | src/test/java/org/wmaop/aop/matcher/MatchResultTest.java | // Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
| import static org.junit.Assert.*;
import org.junit.Test;
import org.wmaop.aop.matcher.MatchResult; | package org.wmaop.aop.matcher;
public class MatchResultTest {
@Test
public void shouldMatchTrue() { | // Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
// Path: src/test/java/org/wmaop/aop/matcher/MatchResultTest.java
import static org.junit.Assert.*;
import org.junit.Test;
import org.wmaop.aop.matcher.MatchResult;
package org.wmaop.aop.matcher;
public class MatchResultTest {
@Test
public void shouldMatchTrue() { | MatchResult mrt = new MatchResult(true, "foo"); |
wmaop/wm-aop | src/test/java/org/wmaop/aop/pointcut/ServicePipelinePointCutTest.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/Matcher.java
// public interface Matcher<T> {
// MatchResult match(T value);
//
// Map<String, Object> toMap();
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import org.wmaop.aop.matcher.MatchResult;
import org.wmaop.aop.matcher.Matcher;
import com.wm.data.IData; | package org.wmaop.aop.pointcut;
public class ServicePipelinePointCutTest {
private FlowPosition pipelinePosition; | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/Matcher.java
// public interface Matcher<T> {
// MatchResult match(T value);
//
// Map<String, Object> toMap();
// }
// Path: src/test/java/org/wmaop/aop/pointcut/ServicePipelinePointCutTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import org.wmaop.aop.matcher.MatchResult;
import org.wmaop.aop.matcher.Matcher;
import com.wm.data.IData;
package org.wmaop.aop.pointcut;
public class ServicePipelinePointCutTest {
private FlowPosition pipelinePosition; | private FlowPositionMatcher serviceNameMatcher; |
wmaop/wm-aop | src/test/java/org/wmaop/aop/pointcut/ServicePipelinePointCutTest.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/Matcher.java
// public interface Matcher<T> {
// MatchResult match(T value);
//
// Map<String, Object> toMap();
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import org.wmaop.aop.matcher.MatchResult;
import org.wmaop.aop.matcher.Matcher;
import com.wm.data.IData; | package org.wmaop.aop.pointcut;
public class ServicePipelinePointCutTest {
private FlowPosition pipelinePosition;
private FlowPositionMatcher serviceNameMatcher;
private IData idata; | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/Matcher.java
// public interface Matcher<T> {
// MatchResult match(T value);
//
// Map<String, Object> toMap();
// }
// Path: src/test/java/org/wmaop/aop/pointcut/ServicePipelinePointCutTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import org.wmaop.aop.matcher.MatchResult;
import org.wmaop.aop.matcher.Matcher;
import com.wm.data.IData;
package org.wmaop.aop.pointcut;
public class ServicePipelinePointCutTest {
private FlowPosition pipelinePosition;
private FlowPositionMatcher serviceNameMatcher;
private IData idata; | private Matcher<? super IData> pipelineMatcher; |
wmaop/wm-aop | src/test/java/org/wmaop/aop/pointcut/ServicePipelinePointCutTest.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/Matcher.java
// public interface Matcher<T> {
// MatchResult match(T value);
//
// Map<String, Object> toMap();
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import org.wmaop.aop.matcher.MatchResult;
import org.wmaop.aop.matcher.Matcher;
import com.wm.data.IData; | package org.wmaop.aop.pointcut;
public class ServicePipelinePointCutTest {
private FlowPosition pipelinePosition;
private FlowPositionMatcher serviceNameMatcher;
private IData idata;
private Matcher<? super IData> pipelineMatcher;
@Before
@SuppressWarnings("unchecked")
public void setUp() {
pipelinePosition = mock(FlowPosition.class);
serviceNameMatcher = mock(FlowPositionMatcher.class);
idata = mock(IData.class);
pipelineMatcher = mock(Matcher.class);
}
@Test
public void shouldBeApplicable() {
| // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/Matcher.java
// public interface Matcher<T> {
// MatchResult match(T value);
//
// Map<String, Object> toMap();
// }
// Path: src/test/java/org/wmaop/aop/pointcut/ServicePipelinePointCutTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import org.wmaop.aop.matcher.MatchResult;
import org.wmaop.aop.matcher.Matcher;
import com.wm.data.IData;
package org.wmaop.aop.pointcut;
public class ServicePipelinePointCutTest {
private FlowPosition pipelinePosition;
private FlowPositionMatcher serviceNameMatcher;
private IData idata;
private Matcher<? super IData> pipelineMatcher;
@Before
@SuppressWarnings("unchecked")
public void setUp() {
pipelinePosition = mock(FlowPosition.class);
serviceNameMatcher = mock(FlowPositionMatcher.class);
idata = mock(IData.class);
pipelineMatcher = mock(Matcher.class);
}
@Test
public void shouldBeApplicable() {
| when(serviceNameMatcher.match(pipelinePosition)).thenReturn(MatchResult.TRUE); |
wmaop/wm-aop | src/test/java/org/wmaop/aop/pointcut/ServicePipelinePointCutTest.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/Matcher.java
// public interface Matcher<T> {
// MatchResult match(T value);
//
// Map<String, Object> toMap();
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import org.wmaop.aop.matcher.MatchResult;
import org.wmaop.aop.matcher.Matcher;
import com.wm.data.IData; | package org.wmaop.aop.pointcut;
public class ServicePipelinePointCutTest {
private FlowPosition pipelinePosition;
private FlowPositionMatcher serviceNameMatcher;
private IData idata;
private Matcher<? super IData> pipelineMatcher;
@Before
@SuppressWarnings("unchecked")
public void setUp() {
pipelinePosition = mock(FlowPosition.class);
serviceNameMatcher = mock(FlowPositionMatcher.class);
idata = mock(IData.class);
pipelineMatcher = mock(Matcher.class);
}
@Test
public void shouldBeApplicable() {
when(serviceNameMatcher.match(pipelinePosition)).thenReturn(MatchResult.TRUE);
when(pipelineMatcher.match(idata)).thenReturn(MatchResult.TRUE); | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/Matcher.java
// public interface Matcher<T> {
// MatchResult match(T value);
//
// Map<String, Object> toMap();
// }
// Path: src/test/java/org/wmaop/aop/pointcut/ServicePipelinePointCutTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import org.wmaop.aop.matcher.MatchResult;
import org.wmaop.aop.matcher.Matcher;
import com.wm.data.IData;
package org.wmaop.aop.pointcut;
public class ServicePipelinePointCutTest {
private FlowPosition pipelinePosition;
private FlowPositionMatcher serviceNameMatcher;
private IData idata;
private Matcher<? super IData> pipelineMatcher;
@Before
@SuppressWarnings("unchecked")
public void setUp() {
pipelinePosition = mock(FlowPosition.class);
serviceNameMatcher = mock(FlowPositionMatcher.class);
idata = mock(IData.class);
pipelineMatcher = mock(Matcher.class);
}
@Test
public void shouldBeApplicable() {
when(serviceNameMatcher.match(pipelinePosition)).thenReturn(MatchResult.TRUE);
when(pipelineMatcher.match(idata)).thenReturn(MatchResult.TRUE); | ServicePipelinePointCut sppc = new ServicePipelinePointCut(serviceNameMatcher, pipelineMatcher, InterceptPoint.INVOKE); |
wmaop/wm-aop | src/test/java/org/wmaop/aop/matcher/CallingServicePositionMatcherTest.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
| import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Stack;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import com.wm.app.b2b.server.InvokeState;
import com.wm.app.b2b.server.Package;
import com.wm.lang.ns.NSName;
import com.wm.lang.ns.NSService;
| package org.wmaop.aop.matcher;
@RunWith(PowerMockRunner.class)
@PrepareForTest(InvokeState.class)
public class CallingServicePositionMatcherTest {
private static final String PUB_FOO_BAR = "pub.foo:bar";
@Test
public void shouldMatchCorrectNamespacePackage() {
NSName nsnTestService = NSName.create("org.wmaop.pub:testService");
NSName nsnBarService = NSName.create(PUB_FOO_BAR);
Package pkg1 = mock(Package.class);
when(pkg1.getName()).thenReturn("pkg1");
Package pkg2 = mock(Package.class);
when(pkg2.getName()).thenReturn("pkg2");
PowerMockito.mockStatic(InvokeState.class);
InvokeState mockInvokeState = mock(InvokeState.class);
when(InvokeState.getCurrentState()).thenReturn(mockInvokeState);
NSService svcTest = mock(NSService.class);
when(svcTest.getNSName()).thenReturn(nsnTestService);
when(svcTest.getPackage()).thenReturn(pkg1);
NSService svcBar = mock(NSService.class);
when(svcBar.getNSName()).thenReturn(nsnBarService);
when(svcBar.getPackage()).thenReturn(pkg2);
Stack<NSService> callStack = new Stack<>();
callStack.push(svcTest);
callStack.push(svcBar);
when(mockInvokeState.getCallStack()).thenReturn(callStack);
| // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
// Path: src/test/java/org/wmaop/aop/matcher/CallingServicePositionMatcherTest.java
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Stack;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import com.wm.app.b2b.server.InvokeState;
import com.wm.app.b2b.server.Package;
import com.wm.lang.ns.NSName;
import com.wm.lang.ns.NSService;
package org.wmaop.aop.matcher;
@RunWith(PowerMockRunner.class)
@PrepareForTest(InvokeState.class)
public class CallingServicePositionMatcherTest {
private static final String PUB_FOO_BAR = "pub.foo:bar";
@Test
public void shouldMatchCorrectNamespacePackage() {
NSName nsnTestService = NSName.create("org.wmaop.pub:testService");
NSName nsnBarService = NSName.create(PUB_FOO_BAR);
Package pkg1 = mock(Package.class);
when(pkg1.getName()).thenReturn("pkg1");
Package pkg2 = mock(Package.class);
when(pkg2.getName()).thenReturn("pkg2");
PowerMockito.mockStatic(InvokeState.class);
InvokeState mockInvokeState = mock(InvokeState.class);
when(InvokeState.getCurrentState()).thenReturn(mockInvokeState);
NSService svcTest = mock(NSService.class);
when(svcTest.getNSName()).thenReturn(nsnTestService);
when(svcTest.getPackage()).thenReturn(pkg1);
NSService svcBar = mock(NSService.class);
when(svcBar.getNSName()).thenReturn(nsnBarService);
when(svcBar.getPackage()).thenReturn(pkg2);
Stack<NSService> callStack = new Stack<>();
callStack.push(svcTest);
callStack.push(svcBar);
when(mockInvokeState.getCallStack()).thenReturn(callStack);
| FlowPosition fp = new FlowPosition(InterceptPoint.INVOKE, PUB_FOO_BAR);
|
wmaop/wm-aop | src/test/java/org/wmaop/aop/matcher/CallingServicePositionMatcherTest.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
| import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Stack;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import com.wm.app.b2b.server.InvokeState;
import com.wm.app.b2b.server.Package;
import com.wm.lang.ns.NSName;
import com.wm.lang.ns.NSService;
| package org.wmaop.aop.matcher;
@RunWith(PowerMockRunner.class)
@PrepareForTest(InvokeState.class)
public class CallingServicePositionMatcherTest {
private static final String PUB_FOO_BAR = "pub.foo:bar";
@Test
public void shouldMatchCorrectNamespacePackage() {
NSName nsnTestService = NSName.create("org.wmaop.pub:testService");
NSName nsnBarService = NSName.create(PUB_FOO_BAR);
Package pkg1 = mock(Package.class);
when(pkg1.getName()).thenReturn("pkg1");
Package pkg2 = mock(Package.class);
when(pkg2.getName()).thenReturn("pkg2");
PowerMockito.mockStatic(InvokeState.class);
InvokeState mockInvokeState = mock(InvokeState.class);
when(InvokeState.getCurrentState()).thenReturn(mockInvokeState);
NSService svcTest = mock(NSService.class);
when(svcTest.getNSName()).thenReturn(nsnTestService);
when(svcTest.getPackage()).thenReturn(pkg1);
NSService svcBar = mock(NSService.class);
when(svcBar.getNSName()).thenReturn(nsnBarService);
when(svcBar.getPackage()).thenReturn(pkg2);
Stack<NSService> callStack = new Stack<>();
callStack.push(svcTest);
callStack.push(svcBar);
when(mockInvokeState.getCallStack()).thenReturn(callStack);
| // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
// Path: src/test/java/org/wmaop/aop/matcher/CallingServicePositionMatcherTest.java
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Stack;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import com.wm.app.b2b.server.InvokeState;
import com.wm.app.b2b.server.Package;
import com.wm.lang.ns.NSName;
import com.wm.lang.ns.NSService;
package org.wmaop.aop.matcher;
@RunWith(PowerMockRunner.class)
@PrepareForTest(InvokeState.class)
public class CallingServicePositionMatcherTest {
private static final String PUB_FOO_BAR = "pub.foo:bar";
@Test
public void shouldMatchCorrectNamespacePackage() {
NSName nsnTestService = NSName.create("org.wmaop.pub:testService");
NSName nsnBarService = NSName.create(PUB_FOO_BAR);
Package pkg1 = mock(Package.class);
when(pkg1.getName()).thenReturn("pkg1");
Package pkg2 = mock(Package.class);
when(pkg2.getName()).thenReturn("pkg2");
PowerMockito.mockStatic(InvokeState.class);
InvokeState mockInvokeState = mock(InvokeState.class);
when(InvokeState.getCurrentState()).thenReturn(mockInvokeState);
NSService svcTest = mock(NSService.class);
when(svcTest.getNSName()).thenReturn(nsnTestService);
when(svcTest.getPackage()).thenReturn(pkg1);
NSService svcBar = mock(NSService.class);
when(svcBar.getNSName()).thenReturn(nsnBarService);
when(svcBar.getPackage()).thenReturn(pkg2);
Stack<NSService> callStack = new Stack<>();
callStack.push(svcTest);
callStack.push(svcBar);
when(mockInvokeState.getCallStack()).thenReturn(callStack);
| FlowPosition fp = new FlowPosition(InterceptPoint.INVOKE, PUB_FOO_BAR);
|
wmaop/wm-aop | src/main/java/org/wmaop/aop/pointcut/ServicePipelinePointCut.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/Matcher.java
// public interface Matcher<T> {
// MatchResult match(T value);
//
// Map<String, Object> toMap();
// }
| import java.util.HashMap;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import org.wmaop.aop.matcher.Matcher;
import com.wm.data.IData; | package org.wmaop.aop.pointcut;
public class ServicePipelinePointCut implements PointCut {
private final FlowPositionMatcher flowPositionMatcher; | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/Matcher.java
// public interface Matcher<T> {
// MatchResult match(T value);
//
// Map<String, Object> toMap();
// }
// Path: src/main/java/org/wmaop/aop/pointcut/ServicePipelinePointCut.java
import java.util.HashMap;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import org.wmaop.aop.matcher.Matcher;
import com.wm.data.IData;
package org.wmaop.aop.pointcut;
public class ServicePipelinePointCut implements PointCut {
private final FlowPositionMatcher flowPositionMatcher; | private final Matcher<? super IData> pipelineMatcher; |
wmaop/wm-aop | src/main/java/org/wmaop/aop/pointcut/ServicePipelinePointCut.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/Matcher.java
// public interface Matcher<T> {
// MatchResult match(T value);
//
// Map<String, Object> toMap();
// }
| import java.util.HashMap;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import org.wmaop.aop.matcher.Matcher;
import com.wm.data.IData; | package org.wmaop.aop.pointcut;
public class ServicePipelinePointCut implements PointCut {
private final FlowPositionMatcher flowPositionMatcher;
private final Matcher<? super IData> pipelineMatcher; | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/Matcher.java
// public interface Matcher<T> {
// MatchResult match(T value);
//
// Map<String, Object> toMap();
// }
// Path: src/main/java/org/wmaop/aop/pointcut/ServicePipelinePointCut.java
import java.util.HashMap;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import org.wmaop.aop.matcher.Matcher;
import com.wm.data.IData;
package org.wmaop.aop.pointcut;
public class ServicePipelinePointCut implements PointCut {
private final FlowPositionMatcher flowPositionMatcher;
private final Matcher<? super IData> pipelineMatcher; | private InterceptPoint interceptPoint; |
wmaop/wm-aop | src/main/java/org/wmaop/aop/pointcut/ServicePipelinePointCut.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/Matcher.java
// public interface Matcher<T> {
// MatchResult match(T value);
//
// Map<String, Object> toMap();
// }
| import java.util.HashMap;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import org.wmaop.aop.matcher.Matcher;
import com.wm.data.IData; | package org.wmaop.aop.pointcut;
public class ServicePipelinePointCut implements PointCut {
private final FlowPositionMatcher flowPositionMatcher;
private final Matcher<? super IData> pipelineMatcher;
private InterceptPoint interceptPoint;
public ServicePipelinePointCut(FlowPositionMatcher flowPositionMatcher, Matcher<? super IData> pipelineMatcher, InterceptPoint interceptPoint) {
this.flowPositionMatcher = flowPositionMatcher;
this.pipelineMatcher = pipelineMatcher;
this.interceptPoint = interceptPoint;
}
@Override | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/Matcher.java
// public interface Matcher<T> {
// MatchResult match(T value);
//
// Map<String, Object> toMap();
// }
// Path: src/main/java/org/wmaop/aop/pointcut/ServicePipelinePointCut.java
import java.util.HashMap;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import org.wmaop.aop.matcher.Matcher;
import com.wm.data.IData;
package org.wmaop.aop.pointcut;
public class ServicePipelinePointCut implements PointCut {
private final FlowPositionMatcher flowPositionMatcher;
private final Matcher<? super IData> pipelineMatcher;
private InterceptPoint interceptPoint;
public ServicePipelinePointCut(FlowPositionMatcher flowPositionMatcher, Matcher<? super IData> pipelineMatcher, InterceptPoint interceptPoint) {
this.flowPositionMatcher = flowPositionMatcher;
this.pipelineMatcher = pipelineMatcher;
this.interceptPoint = interceptPoint;
}
@Override | public boolean isApplicable(FlowPosition pipelinePosition, IData idata) { |
wmaop/wm-aop | src/main/java/org/wmaop/aop/matcher/jexl/JexlFlowPositionMatcher.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
| import java.util.HashMap;
import java.util.Map;
import org.apache.commons.jexl3.JexlExpression;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.MapContext;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import org.wmaop.aop.matcher.MatchResult;
import org.wmaop.util.jexl.JexlExpressionFactory;
| package org.wmaop.aop.matcher.jexl;
@Deprecated
public class JexlFlowPositionMatcher implements FlowPositionMatcher {
private final JexlExpression expression;
private final String sid;
public JexlFlowPositionMatcher(String sid, String expr) {
this.sid = sid;
expression = createExpression(sid, expr);
}
| // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
// Path: src/main/java/org/wmaop/aop/matcher/jexl/JexlFlowPositionMatcher.java
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.jexl3.JexlExpression;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.MapContext;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import org.wmaop.aop.matcher.MatchResult;
import org.wmaop.util.jexl.JexlExpressionFactory;
package org.wmaop.aop.matcher.jexl;
@Deprecated
public class JexlFlowPositionMatcher implements FlowPositionMatcher {
private final JexlExpression expression;
private final String sid;
public JexlFlowPositionMatcher(String sid, String expr) {
this.sid = sid;
expression = createExpression(sid, expr);
}
| public MatchResult match(FlowPosition flowPosition) {
|
wmaop/wm-aop | src/main/java/org/wmaop/aop/matcher/jexl/JexlFlowPositionMatcher.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
| import java.util.HashMap;
import java.util.Map;
import org.apache.commons.jexl3.JexlExpression;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.MapContext;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import org.wmaop.aop.matcher.MatchResult;
import org.wmaop.util.jexl.JexlExpressionFactory;
| package org.wmaop.aop.matcher.jexl;
@Deprecated
public class JexlFlowPositionMatcher implements FlowPositionMatcher {
private final JexlExpression expression;
private final String sid;
public JexlFlowPositionMatcher(String sid, String expr) {
this.sid = sid;
expression = createExpression(sid, expr);
}
| // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
// Path: src/main/java/org/wmaop/aop/matcher/jexl/JexlFlowPositionMatcher.java
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.jexl3.JexlExpression;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.MapContext;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import org.wmaop.aop.matcher.MatchResult;
import org.wmaop.util.jexl.JexlExpressionFactory;
package org.wmaop.aop.matcher.jexl;
@Deprecated
public class JexlFlowPositionMatcher implements FlowPositionMatcher {
private final JexlExpression expression;
private final String sid;
public JexlFlowPositionMatcher(String sid, String expr) {
this.sid = sid;
expression = createExpression(sid, expr);
}
| public MatchResult match(FlowPosition flowPosition) {
|
wmaop/wm-aop | src/main/java/org/wmaop/aop/advice/Advice.java | // Path: src/main/java/org/wmaop/aop/advice/remit/Remit.java
// public interface Remit {
// boolean isApplicable();
// boolean isApplicable(Scope scope);
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/Interceptor.java
// public interface Interceptor {
//
// InterceptResult intercept(FlowPosition flowPosition, IData idata);
//
// int getInvokeCount();
//
// String getName();
//
// Map<String, Object> toMap();
//
// }
//
// Path: src/main/java/org/wmaop/aop/pointcut/PointCut.java
// public interface PointCut {
//
// boolean isApplicable(FlowPosition pipelinePosition, IData idata);
//
// InterceptPoint getInterceptPoint();
//
// FlowPositionMatcher getFlowPositionMatcher();
//
// Object toMap();
// }
| import java.util.HashMap;
import java.util.Map;
import org.wmaop.aop.advice.remit.Remit;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.Interceptor;
import org.wmaop.aop.pointcut.PointCut;
import com.wm.data.IData; | package org.wmaop.aop.advice;
public class Advice {
private final PointCut pointCut; | // Path: src/main/java/org/wmaop/aop/advice/remit/Remit.java
// public interface Remit {
// boolean isApplicable();
// boolean isApplicable(Scope scope);
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/Interceptor.java
// public interface Interceptor {
//
// InterceptResult intercept(FlowPosition flowPosition, IData idata);
//
// int getInvokeCount();
//
// String getName();
//
// Map<String, Object> toMap();
//
// }
//
// Path: src/main/java/org/wmaop/aop/pointcut/PointCut.java
// public interface PointCut {
//
// boolean isApplicable(FlowPosition pipelinePosition, IData idata);
//
// InterceptPoint getInterceptPoint();
//
// FlowPositionMatcher getFlowPositionMatcher();
//
// Object toMap();
// }
// Path: src/main/java/org/wmaop/aop/advice/Advice.java
import java.util.HashMap;
import java.util.Map;
import org.wmaop.aop.advice.remit.Remit;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.Interceptor;
import org.wmaop.aop.pointcut.PointCut;
import com.wm.data.IData;
package org.wmaop.aop.advice;
public class Advice {
private final PointCut pointCut; | private final Interceptor interceptor; |
wmaop/wm-aop | src/main/java/org/wmaop/aop/advice/Advice.java | // Path: src/main/java/org/wmaop/aop/advice/remit/Remit.java
// public interface Remit {
// boolean isApplicable();
// boolean isApplicable(Scope scope);
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/Interceptor.java
// public interface Interceptor {
//
// InterceptResult intercept(FlowPosition flowPosition, IData idata);
//
// int getInvokeCount();
//
// String getName();
//
// Map<String, Object> toMap();
//
// }
//
// Path: src/main/java/org/wmaop/aop/pointcut/PointCut.java
// public interface PointCut {
//
// boolean isApplicable(FlowPosition pipelinePosition, IData idata);
//
// InterceptPoint getInterceptPoint();
//
// FlowPositionMatcher getFlowPositionMatcher();
//
// Object toMap();
// }
| import java.util.HashMap;
import java.util.Map;
import org.wmaop.aop.advice.remit.Remit;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.Interceptor;
import org.wmaop.aop.pointcut.PointCut;
import com.wm.data.IData; | package org.wmaop.aop.advice;
public class Advice {
private final PointCut pointCut;
private final Interceptor interceptor;
private final String id;
private AdviceState adviceState = AdviceState.NEW; | // Path: src/main/java/org/wmaop/aop/advice/remit/Remit.java
// public interface Remit {
// boolean isApplicable();
// boolean isApplicable(Scope scope);
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/Interceptor.java
// public interface Interceptor {
//
// InterceptResult intercept(FlowPosition flowPosition, IData idata);
//
// int getInvokeCount();
//
// String getName();
//
// Map<String, Object> toMap();
//
// }
//
// Path: src/main/java/org/wmaop/aop/pointcut/PointCut.java
// public interface PointCut {
//
// boolean isApplicable(FlowPosition pipelinePosition, IData idata);
//
// InterceptPoint getInterceptPoint();
//
// FlowPositionMatcher getFlowPositionMatcher();
//
// Object toMap();
// }
// Path: src/main/java/org/wmaop/aop/advice/Advice.java
import java.util.HashMap;
import java.util.Map;
import org.wmaop.aop.advice.remit.Remit;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.Interceptor;
import org.wmaop.aop.pointcut.PointCut;
import com.wm.data.IData;
package org.wmaop.aop.advice;
public class Advice {
private final PointCut pointCut;
private final Interceptor interceptor;
private final String id;
private AdviceState adviceState = AdviceState.NEW; | private final Remit remit; |
wmaop/wm-aop | src/main/java/org/wmaop/aop/advice/Advice.java | // Path: src/main/java/org/wmaop/aop/advice/remit/Remit.java
// public interface Remit {
// boolean isApplicable();
// boolean isApplicable(Scope scope);
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/Interceptor.java
// public interface Interceptor {
//
// InterceptResult intercept(FlowPosition flowPosition, IData idata);
//
// int getInvokeCount();
//
// String getName();
//
// Map<String, Object> toMap();
//
// }
//
// Path: src/main/java/org/wmaop/aop/pointcut/PointCut.java
// public interface PointCut {
//
// boolean isApplicable(FlowPosition pipelinePosition, IData idata);
//
// InterceptPoint getInterceptPoint();
//
// FlowPositionMatcher getFlowPositionMatcher();
//
// Object toMap();
// }
| import java.util.HashMap;
import java.util.Map;
import org.wmaop.aop.advice.remit.Remit;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.Interceptor;
import org.wmaop.aop.pointcut.PointCut;
import com.wm.data.IData; | package org.wmaop.aop.advice;
public class Advice {
private final PointCut pointCut;
private final Interceptor interceptor;
private final String id;
private AdviceState adviceState = AdviceState.NEW;
private final Remit remit;
public Advice(String id, Remit remit, PointCut pointCut, Interceptor interceptor) {
this.pointCut = pointCut;
this.interceptor = interceptor;
this.id = id;
this.remit = remit;
}
public Remit getRemit() {
return remit;
}
public PointCut getPointCut() {
return pointCut;
}
| // Path: src/main/java/org/wmaop/aop/advice/remit/Remit.java
// public interface Remit {
// boolean isApplicable();
// boolean isApplicable(Scope scope);
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/Interceptor.java
// public interface Interceptor {
//
// InterceptResult intercept(FlowPosition flowPosition, IData idata);
//
// int getInvokeCount();
//
// String getName();
//
// Map<String, Object> toMap();
//
// }
//
// Path: src/main/java/org/wmaop/aop/pointcut/PointCut.java
// public interface PointCut {
//
// boolean isApplicable(FlowPosition pipelinePosition, IData idata);
//
// InterceptPoint getInterceptPoint();
//
// FlowPositionMatcher getFlowPositionMatcher();
//
// Object toMap();
// }
// Path: src/main/java/org/wmaop/aop/advice/Advice.java
import java.util.HashMap;
import java.util.Map;
import org.wmaop.aop.advice.remit.Remit;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.Interceptor;
import org.wmaop.aop.pointcut.PointCut;
import com.wm.data.IData;
package org.wmaop.aop.advice;
public class Advice {
private final PointCut pointCut;
private final Interceptor interceptor;
private final String id;
private AdviceState adviceState = AdviceState.NEW;
private final Remit remit;
public Advice(String id, Remit remit, PointCut pointCut, Interceptor interceptor) {
this.pointCut = pointCut;
this.interceptor = interceptor;
this.id = id;
this.remit = remit;
}
public Remit getRemit() {
return remit;
}
public PointCut getPointCut() {
return pointCut;
}
| public boolean isApplicable(FlowPosition pipelinePosition, IData idata){ |
wmaop/wm-aop | src/test/java/org/wmaop/aop/advice/remit/GlobalRemitTest.java | // Path: src/main/java/org/wmaop/aop/advice/Scope.java
// public enum Scope {
// ALL, GLOBAL, SESSION, USER;
// }
| import static org.junit.Assert.*;
import org.junit.Test;
import org.wmaop.aop.advice.Scope; | package org.wmaop.aop.advice.remit;
public class GlobalRemitTest {
@Test
public void shouldExerciseScopeApplicability() {
GlobalRemit gr = new GlobalRemit();
assertTrue(gr.isApplicable()); | // Path: src/main/java/org/wmaop/aop/advice/Scope.java
// public enum Scope {
// ALL, GLOBAL, SESSION, USER;
// }
// Path: src/test/java/org/wmaop/aop/advice/remit/GlobalRemitTest.java
import static org.junit.Assert.*;
import org.junit.Test;
import org.wmaop.aop.advice.Scope;
package org.wmaop.aop.advice.remit;
public class GlobalRemitTest {
@Test
public void shouldExerciseScopeApplicability() {
GlobalRemit gr = new GlobalRemit();
assertTrue(gr.isApplicable()); | assertTrue(gr.isApplicable(Scope.ALL)); |
wmaop/wm-aop | src/test/java/org/wmaop/interceptor/assertion/AssertionInterceptorTest.java | // Path: src/main/java/org/wmaop/aop/assertion/AssertionInterceptor.java
// public class AssertionInterceptor implements Interceptor, Assertable {
//
// private final String assertionName;
// private int invokeCount = 0;
// private boolean asserted;
//
// public AssertionInterceptor(String assertionName) {
// this.assertionName = assertionName;
// }
//
// public boolean performAssert(IData idata) {
// return true;
// }
//
// public void reset() {
// invokeCount = 0;
// asserted = false;
// }
//
// @Override
// public final InterceptResult intercept(FlowPosition flowPosition, IData idata) {
// invokeCount++;
// if (performAssert(idata)) {
// asserted = true;
// }
// return InterceptResult.FALSE;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// public boolean hasAsserted() {
// return asserted;
// }
//
// @Override
// public String getName() {
// return assertionName;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("assertionName", assertionName);
// am.put("invokeCount", invokeCount);
// am.put("asserted", Boolean.toString(asserted));
// return am;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import org.junit.Test;
import org.wmaop.aop.assertion.AssertionInterceptor;
import org.wmaop.aop.interceptor.FlowPosition;
import com.wm.data.IData; | package org.wmaop.interceptor.assertion;
public class AssertionInterceptorTest {
@Test
public void shouldExerciseAll() { | // Path: src/main/java/org/wmaop/aop/assertion/AssertionInterceptor.java
// public class AssertionInterceptor implements Interceptor, Assertable {
//
// private final String assertionName;
// private int invokeCount = 0;
// private boolean asserted;
//
// public AssertionInterceptor(String assertionName) {
// this.assertionName = assertionName;
// }
//
// public boolean performAssert(IData idata) {
// return true;
// }
//
// public void reset() {
// invokeCount = 0;
// asserted = false;
// }
//
// @Override
// public final InterceptResult intercept(FlowPosition flowPosition, IData idata) {
// invokeCount++;
// if (performAssert(idata)) {
// asserted = true;
// }
// return InterceptResult.FALSE;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// public boolean hasAsserted() {
// return asserted;
// }
//
// @Override
// public String getName() {
// return assertionName;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("assertionName", assertionName);
// am.put("invokeCount", invokeCount);
// am.put("asserted", Boolean.toString(asserted));
// return am;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
// Path: src/test/java/org/wmaop/interceptor/assertion/AssertionInterceptorTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import org.junit.Test;
import org.wmaop.aop.assertion.AssertionInterceptor;
import org.wmaop.aop.interceptor.FlowPosition;
import com.wm.data.IData;
package org.wmaop.interceptor.assertion;
public class AssertionInterceptorTest {
@Test
public void shouldExerciseAll() { | AssertionInterceptor ai = new AssertionInterceptor("foo"); |
wmaop/wm-aop | src/test/java/org/wmaop/interceptor/assertion/AssertionInterceptorTest.java | // Path: src/main/java/org/wmaop/aop/assertion/AssertionInterceptor.java
// public class AssertionInterceptor implements Interceptor, Assertable {
//
// private final String assertionName;
// private int invokeCount = 0;
// private boolean asserted;
//
// public AssertionInterceptor(String assertionName) {
// this.assertionName = assertionName;
// }
//
// public boolean performAssert(IData idata) {
// return true;
// }
//
// public void reset() {
// invokeCount = 0;
// asserted = false;
// }
//
// @Override
// public final InterceptResult intercept(FlowPosition flowPosition, IData idata) {
// invokeCount++;
// if (performAssert(idata)) {
// asserted = true;
// }
// return InterceptResult.FALSE;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// public boolean hasAsserted() {
// return asserted;
// }
//
// @Override
// public String getName() {
// return assertionName;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("assertionName", assertionName);
// am.put("invokeCount", invokeCount);
// am.put("asserted", Boolean.toString(asserted));
// return am;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import org.junit.Test;
import org.wmaop.aop.assertion.AssertionInterceptor;
import org.wmaop.aop.interceptor.FlowPosition;
import com.wm.data.IData; | package org.wmaop.interceptor.assertion;
public class AssertionInterceptorTest {
@Test
public void shouldExerciseAll() {
AssertionInterceptor ai = new AssertionInterceptor("foo");
assertEquals("foo", ai.getName());
assertEquals(0, ai.getInvokeCount());
assertFalse(ai.hasAsserted());
| // Path: src/main/java/org/wmaop/aop/assertion/AssertionInterceptor.java
// public class AssertionInterceptor implements Interceptor, Assertable {
//
// private final String assertionName;
// private int invokeCount = 0;
// private boolean asserted;
//
// public AssertionInterceptor(String assertionName) {
// this.assertionName = assertionName;
// }
//
// public boolean performAssert(IData idata) {
// return true;
// }
//
// public void reset() {
// invokeCount = 0;
// asserted = false;
// }
//
// @Override
// public final InterceptResult intercept(FlowPosition flowPosition, IData idata) {
// invokeCount++;
// if (performAssert(idata)) {
// asserted = true;
// }
// return InterceptResult.FALSE;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// public boolean hasAsserted() {
// return asserted;
// }
//
// @Override
// public String getName() {
// return assertionName;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("assertionName", assertionName);
// am.put("invokeCount", invokeCount);
// am.put("asserted", Boolean.toString(asserted));
// return am;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
// Path: src/test/java/org/wmaop/interceptor/assertion/AssertionInterceptorTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import org.junit.Test;
import org.wmaop.aop.assertion.AssertionInterceptor;
import org.wmaop.aop.interceptor.FlowPosition;
import com.wm.data.IData;
package org.wmaop.interceptor.assertion;
public class AssertionInterceptorTest {
@Test
public void shouldExerciseAll() {
AssertionInterceptor ai = new AssertionInterceptor("foo");
assertEquals("foo", ai.getName());
assertEquals(0, ai.getInvokeCount());
assertFalse(ai.hasAsserted());
| ai.intercept(mock(FlowPosition.class), mock(IData.class)); |
wmaop/wm-aop | src/main/java/org/wmaop/aop/stub/StubManager.java | // Path: src/main/java/org/wmaop/aop/advice/Advice.java
// public class Advice {
//
// private final PointCut pointCut;
// private final Interceptor interceptor;
// private final String id;
// private AdviceState adviceState = AdviceState.NEW;
// private final Remit remit;
//
// public Advice(String id, Remit remit, PointCut pointCut, Interceptor interceptor) {
// this.pointCut = pointCut;
// this.interceptor = interceptor;
// this.id = id;
// this.remit = remit;
// }
//
// public Remit getRemit() {
// return remit;
// }
//
// public PointCut getPointCut() {
// return pointCut;
// }
//
// public boolean isApplicable(FlowPosition pipelinePosition, IData idata){
// return pointCut.isApplicable(pipelinePosition, idata) && remit.isApplicable();
// }
//
// public Interceptor getInterceptor() {
// return interceptor;
// }
//
// public String getId() {
// return id;
// }
//
// public AdviceState getAdviceState() {
// return adviceState;
// }
//
// public void setAdviceState(AdviceState adviceState) {
// this.adviceState = adviceState;
// }
//
// @Override
// public String toString() {
// return id + ' ' + adviceState + ' ' + pointCut + ' ' + interceptor + ' ' + pointCut.getInterceptPoint() + ' ' + remit;
// }
//
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("state", adviceState.toString());
// am.put("adviceId", id);
// am.put("pointcut", pointCut.toMap());
// am.put("interceptor", interceptor.toMap());
// am.put("remit", remit.toString());
// return am;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Advice other = (Advice) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
// }
| import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.HashSet;
import java.util.Set;
import org.wmaop.aop.advice.Advice;
import org.wmaop.util.logger.Logger;
import com.wm.app.b2b.server.BaseService;
import com.wm.app.b2b.server.Package;
import com.wm.app.b2b.server.PackageManager;
import com.wm.app.b2b.server.ServerAPI;
import com.wm.app.b2b.server.ServiceSetupException;
import com.wm.app.b2b.server.ns.Namespace;
import com.wm.lang.ns.NSException;
import com.wm.lang.ns.NSName;
import com.wm.lang.ns.NSNode;
import com.wm.lang.ns.NSServiceType; | Package pkg = PackageManager.getPackage(SUPPORTING_PKG);
if (pkg != null) {
NSName name = NSName.create(svcName);
BaseService svc = Namespace.getService(name);
if (svc != null && SUPPORTING_PKG.equals(svc.getPackageName())) {
Namespace.current().deleteNode(name, true, pkg);
stubbedServices.remove(svcName);
}
}
}
public void clearStubs() {
Package pkg = PackageManager.getPackage(SUPPORTING_PKG);
if (pkg == null) {
return;
}
for (Object node : Namespace.current().getNodes(pkg)) {
try {
Namespace.current().deleteNode(((NSNode) node).getNSName(), true, pkg);
} catch (NSException e) {
throw new StubLifecycleException("Internal namespace exception clearing stubs", e);
}
}
stubbedServices.clear();
}
public boolean hasStub(String svcName) {
return stubbedServices.contains(svcName);
}
| // Path: src/main/java/org/wmaop/aop/advice/Advice.java
// public class Advice {
//
// private final PointCut pointCut;
// private final Interceptor interceptor;
// private final String id;
// private AdviceState adviceState = AdviceState.NEW;
// private final Remit remit;
//
// public Advice(String id, Remit remit, PointCut pointCut, Interceptor interceptor) {
// this.pointCut = pointCut;
// this.interceptor = interceptor;
// this.id = id;
// this.remit = remit;
// }
//
// public Remit getRemit() {
// return remit;
// }
//
// public PointCut getPointCut() {
// return pointCut;
// }
//
// public boolean isApplicable(FlowPosition pipelinePosition, IData idata){
// return pointCut.isApplicable(pipelinePosition, idata) && remit.isApplicable();
// }
//
// public Interceptor getInterceptor() {
// return interceptor;
// }
//
// public String getId() {
// return id;
// }
//
// public AdviceState getAdviceState() {
// return adviceState;
// }
//
// public void setAdviceState(AdviceState adviceState) {
// this.adviceState = adviceState;
// }
//
// @Override
// public String toString() {
// return id + ' ' + adviceState + ' ' + pointCut + ' ' + interceptor + ' ' + pointCut.getInterceptPoint() + ' ' + remit;
// }
//
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("state", adviceState.toString());
// am.put("adviceId", id);
// am.put("pointcut", pointCut.toMap());
// am.put("interceptor", interceptor.toMap());
// am.put("remit", remit.toString());
// return am;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Advice other = (Advice) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
// }
// Path: src/main/java/org/wmaop/aop/stub/StubManager.java
import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.HashSet;
import java.util.Set;
import org.wmaop.aop.advice.Advice;
import org.wmaop.util.logger.Logger;
import com.wm.app.b2b.server.BaseService;
import com.wm.app.b2b.server.Package;
import com.wm.app.b2b.server.PackageManager;
import com.wm.app.b2b.server.ServerAPI;
import com.wm.app.b2b.server.ServiceSetupException;
import com.wm.app.b2b.server.ns.Namespace;
import com.wm.lang.ns.NSException;
import com.wm.lang.ns.NSName;
import com.wm.lang.ns.NSNode;
import com.wm.lang.ns.NSServiceType;
Package pkg = PackageManager.getPackage(SUPPORTING_PKG);
if (pkg != null) {
NSName name = NSName.create(svcName);
BaseService svc = Namespace.getService(name);
if (svc != null && SUPPORTING_PKG.equals(svc.getPackageName())) {
Namespace.current().deleteNode(name, true, pkg);
stubbedServices.remove(svcName);
}
}
}
public void clearStubs() {
Package pkg = PackageManager.getPackage(SUPPORTING_PKG);
if (pkg == null) {
return;
}
for (Object node : Namespace.current().getNodes(pkg)) {
try {
Namespace.current().deleteNode(((NSNode) node).getNSName(), true, pkg);
} catch (NSException e) {
throw new StubLifecycleException("Internal namespace exception clearing stubs", e);
}
}
stubbedServices.clear();
}
public boolean hasStub(String svcName) {
return stubbedServices.contains(svcName);
}
| public boolean hasStub(Advice advice) { |
wmaop/wm-aop | src/test/java/org/wmaop/aop/advice/remit/UserRemitTest.java | // Path: src/main/java/org/wmaop/aop/advice/Scope.java
// public enum Scope {
// ALL, GLOBAL, SESSION, USER;
// }
| import static org.junit.Assert.*;
import org.junit.Test;
import org.wmaop.aop.advice.Scope; | package org.wmaop.aop.advice.remit;
public class UserRemitTest {
@Test
public void shouldReflectDiscoveredUserScope() {
UserRemit ur = new UserRemit();
assertFalse(ur.isApplicable(null)); | // Path: src/main/java/org/wmaop/aop/advice/Scope.java
// public enum Scope {
// ALL, GLOBAL, SESSION, USER;
// }
// Path: src/test/java/org/wmaop/aop/advice/remit/UserRemitTest.java
import static org.junit.Assert.*;
import org.junit.Test;
import org.wmaop.aop.advice.Scope;
package org.wmaop.aop.advice.remit;
public class UserRemitTest {
@Test
public void shouldReflectDiscoveredUserScope() {
UserRemit ur = new UserRemit();
assertFalse(ur.isApplicable(null)); | assertTrue(ur.isApplicable(Scope.ALL)); |
wmaop/wm-aop | src/main/java/org/wmaop/aop/matcher/jexl/JexlServiceNameMatcher.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/Matcher.java
// public interface Matcher<T> {
// MatchResult match(T value);
//
// Map<String, Object> toMap();
// }
| import java.util.HashMap;
import java.util.Map;
import org.apache.commons.jexl3.JexlExpression;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.MapContext;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.matcher.MatchResult;
import org.wmaop.aop.matcher.Matcher;
import org.wmaop.util.jexl.JexlExpressionFactory; | package org.wmaop.aop.matcher.jexl;
public class JexlServiceNameMatcher implements Matcher<FlowPosition> {
private final JexlExpression expression;
private final String sid;
public JexlServiceNameMatcher(String sid, String expr) {
this.sid = sid;
expression = createExpression(sid, expr);
}
@Override | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/Matcher.java
// public interface Matcher<T> {
// MatchResult match(T value);
//
// Map<String, Object> toMap();
// }
// Path: src/main/java/org/wmaop/aop/matcher/jexl/JexlServiceNameMatcher.java
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.jexl3.JexlExpression;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.MapContext;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.matcher.MatchResult;
import org.wmaop.aop.matcher.Matcher;
import org.wmaop.util.jexl.JexlExpressionFactory;
package org.wmaop.aop.matcher.jexl;
public class JexlServiceNameMatcher implements Matcher<FlowPosition> {
private final JexlExpression expression;
private final String sid;
public JexlServiceNameMatcher(String sid, String expr) {
this.sid = sid;
expression = createExpression(sid, expr);
}
@Override | public MatchResult match(FlowPosition flowPosition) { |
wmaop/wm-aop | src/main/java/org/wmaop/aop/pointcut/PointCut.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
| import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import com.wm.data.IData; | package org.wmaop.aop.pointcut;
public interface PointCut {
boolean isApplicable(FlowPosition pipelinePosition, IData idata);
| // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
// Path: src/main/java/org/wmaop/aop/pointcut/PointCut.java
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import com.wm.data.IData;
package org.wmaop.aop.pointcut;
public interface PointCut {
boolean isApplicable(FlowPosition pipelinePosition, IData idata);
| InterceptPoint getInterceptPoint(); |
wmaop/wm-aop | src/main/java/org/wmaop/aop/pointcut/PointCut.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
| import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import com.wm.data.IData; | package org.wmaop.aop.pointcut;
public interface PointCut {
boolean isApplicable(FlowPosition pipelinePosition, IData idata);
InterceptPoint getInterceptPoint();
| // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcher.java
// public interface FlowPositionMatcher extends Matcher<FlowPosition> {
//
// String getServiceName();
//
// }
// Path: src/main/java/org/wmaop/aop/pointcut/PointCut.java
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.matcher.FlowPositionMatcher;
import com.wm.data.IData;
package org.wmaop.aop.pointcut;
public interface PointCut {
boolean isApplicable(FlowPosition pipelinePosition, IData idata);
InterceptPoint getInterceptPoint();
| FlowPositionMatcher getFlowPositionMatcher(); |
wmaop/wm-aop | src/main/java/org/wmaop/aop/advice/remit/UserRemit.java | // Path: src/main/java/org/wmaop/aop/advice/Scope.java
// public enum Scope {
// ALL, GLOBAL, SESSION, USER;
// }
//
// Path: src/main/java/org/wmaop/aop/advice/Scope.java
// public enum Scope {
// ALL, GLOBAL, SESSION, USER;
// }
| import static org.wmaop.aop.advice.Scope.*;
import org.wmaop.aop.advice.Scope;
import com.wm.app.b2b.server.InvokeState;
import com.wm.app.b2b.server.User; | package org.wmaop.aop.advice.remit;
public class UserRemit implements Remit {
public static final String DEFAULT_USERNAME = "Default";
private String username;
public UserRemit() {
this.username = getCurrentUsername();
}
public UserRemit(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
@Override
public boolean isApplicable() {
return username.equals(getCurrentUsername());
}
@Override | // Path: src/main/java/org/wmaop/aop/advice/Scope.java
// public enum Scope {
// ALL, GLOBAL, SESSION, USER;
// }
//
// Path: src/main/java/org/wmaop/aop/advice/Scope.java
// public enum Scope {
// ALL, GLOBAL, SESSION, USER;
// }
// Path: src/main/java/org/wmaop/aop/advice/remit/UserRemit.java
import static org.wmaop.aop.advice.Scope.*;
import org.wmaop.aop.advice.Scope;
import com.wm.app.b2b.server.InvokeState;
import com.wm.app.b2b.server.User;
package org.wmaop.aop.advice.remit;
public class UserRemit implements Remit {
public static final String DEFAULT_USERNAME = "Default";
private String username;
public UserRemit() {
this.username = getCurrentUsername();
}
public UserRemit(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
@Override
public boolean isApplicable() {
return username.equals(getCurrentUsername());
}
@Override | public boolean isApplicable(Scope scope) { |
wmaop/wm-aop | src/test/java/org/wmaop/chainprocessor/InterceptResultTest.java | // Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.wmaop.aop.interceptor.InterceptResult; | package org.wmaop.chainprocessor;
public class InterceptResultTest {
@Test
public void shouldHaveCorrectDefaults() { | // Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
// Path: src/test/java/org/wmaop/chainprocessor/InterceptResultTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.wmaop.aop.interceptor.InterceptResult;
package org.wmaop.chainprocessor;
public class InterceptResultTest {
@Test
public void shouldHaveCorrectDefaults() { | assertTrue(InterceptResult.TRUE.hasIntercepted()); |
wmaop/wm-aop | src/test/java/org/wmaop/interceptor/mock/canned/CannedResponseInterceptorTest.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/interceptor/mock/canned/CannedResponseInterceptor.java
// public enum ResponseSequence {
// SEQUENTIAL, RANDOM;
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.mockito.Mockito;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.interceptor.mock.canned.CannedResponseInterceptor.ResponseSequence;
import com.wm.data.IData;
import com.wm.data.IDataCursor;
import com.wm.data.IDataUtil;
import com.wm.data.ISMemDataImpl; | package org.wmaop.interceptor.mock.canned;
public class CannedResponseInterceptorTest {
private String A_IDATA = "<IDataXMLCoder version=\"1.0\"><record javaclass=\"com.wm.data.ISMemDataImpl\"><value name=\"akey\">avalue</value></record></IDataXMLCoder>";
@Test
public void shouldLoadFromStream() throws IOException {
IData pipeline = getIData(new String[][]{{"bkey", "bvalue"}}); | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/interceptor/mock/canned/CannedResponseInterceptor.java
// public enum ResponseSequence {
// SEQUENTIAL, RANDOM;
// }
// Path: src/test/java/org/wmaop/interceptor/mock/canned/CannedResponseInterceptorTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.mockito.Mockito;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.interceptor.mock.canned.CannedResponseInterceptor.ResponseSequence;
import com.wm.data.IData;
import com.wm.data.IDataCursor;
import com.wm.data.IDataUtil;
import com.wm.data.ISMemDataImpl;
package org.wmaop.interceptor.mock.canned;
public class CannedResponseInterceptorTest {
private String A_IDATA = "<IDataXMLCoder version=\"1.0\"><record javaclass=\"com.wm.data.ISMemDataImpl\"><value name=\"akey\">avalue</value></record></IDataXMLCoder>";
@Test
public void shouldLoadFromStream() throws IOException {
IData pipeline = getIData(new String[][]{{"bkey", "bvalue"}}); | FlowPosition flowPosition = Mockito.mock(FlowPosition.class); |
wmaop/wm-aop | src/test/java/org/wmaop/interceptor/mock/canned/CannedResponseInterceptorTest.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/interceptor/mock/canned/CannedResponseInterceptor.java
// public enum ResponseSequence {
// SEQUENTIAL, RANDOM;
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.mockito.Mockito;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.interceptor.mock.canned.CannedResponseInterceptor.ResponseSequence;
import com.wm.data.IData;
import com.wm.data.IDataCursor;
import com.wm.data.IDataUtil;
import com.wm.data.ISMemDataImpl; | package org.wmaop.interceptor.mock.canned;
public class CannedResponseInterceptorTest {
private String A_IDATA = "<IDataXMLCoder version=\"1.0\"><record javaclass=\"com.wm.data.ISMemDataImpl\"><value name=\"akey\">avalue</value></record></IDataXMLCoder>";
@Test
public void shouldLoadFromStream() throws IOException {
IData pipeline = getIData(new String[][]{{"bkey", "bvalue"}});
FlowPosition flowPosition = Mockito.mock(FlowPosition.class);
ByteArrayInputStream bais = new ByteArrayInputStream(A_IDATA.getBytes()); | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/interceptor/mock/canned/CannedResponseInterceptor.java
// public enum ResponseSequence {
// SEQUENTIAL, RANDOM;
// }
// Path: src/test/java/org/wmaop/interceptor/mock/canned/CannedResponseInterceptorTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.mockito.Mockito;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.interceptor.mock.canned.CannedResponseInterceptor.ResponseSequence;
import com.wm.data.IData;
import com.wm.data.IDataCursor;
import com.wm.data.IDataUtil;
import com.wm.data.ISMemDataImpl;
package org.wmaop.interceptor.mock.canned;
public class CannedResponseInterceptorTest {
private String A_IDATA = "<IDataXMLCoder version=\"1.0\"><record javaclass=\"com.wm.data.ISMemDataImpl\"><value name=\"akey\">avalue</value></record></IDataXMLCoder>";
@Test
public void shouldLoadFromStream() throws IOException {
IData pipeline = getIData(new String[][]{{"bkey", "bvalue"}});
FlowPosition flowPosition = Mockito.mock(FlowPosition.class);
ByteArrayInputStream bais = new ByteArrayInputStream(A_IDATA.getBytes()); | InterceptResult ir = new CannedResponseInterceptor(bais).intercept(flowPosition , pipeline); |
wmaop/wm-aop | src/test/java/org/wmaop/interceptor/mock/canned/CannedResponseInterceptorTest.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/interceptor/mock/canned/CannedResponseInterceptor.java
// public enum ResponseSequence {
// SEQUENTIAL, RANDOM;
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.mockito.Mockito;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.interceptor.mock.canned.CannedResponseInterceptor.ResponseSequence;
import com.wm.data.IData;
import com.wm.data.IDataCursor;
import com.wm.data.IDataUtil;
import com.wm.data.ISMemDataImpl; | assertTrue(ir.hasIntercepted());
IDataCursor pc = pipeline.getCursor();
assertEquals(2, IDataUtil.size(pc));
assertEquals("avalue", IDataUtil.getString(pc, "akey"));
assertEquals("bvalue", IDataUtil.getString(pc, "bkey"));
}
@Test
public void shouldNotChange() throws IOException {
IData pipeline = getIData(new String[][]{{"bkey", "bvalue"}});
FlowPosition flowPosition = Mockito.mock(FlowPosition.class);
InterceptResult ir = new CannedResponseInterceptor((IData)null).intercept(flowPosition , pipeline);
assertTrue(ir.hasIntercepted());
IDataCursor pc = pipeline.getCursor();
assertEquals(1, IDataUtil.size(pc));
pc.destroy();
}
private IData getIData(String[][] data) {
IData idata = new ISMemDataImpl();
IDataCursor idc = idata.getCursor();
for (String[] kv : data) {
IDataUtil.put(idc, kv[0], kv[1]);
}
idc.destroy();
return idata;
}
@Test
public void shouldReturnSequential() { | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/interceptor/mock/canned/CannedResponseInterceptor.java
// public enum ResponseSequence {
// SEQUENTIAL, RANDOM;
// }
// Path: src/test/java/org/wmaop/interceptor/mock/canned/CannedResponseInterceptorTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.mockito.Mockito;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.interceptor.mock.canned.CannedResponseInterceptor.ResponseSequence;
import com.wm.data.IData;
import com.wm.data.IDataCursor;
import com.wm.data.IDataUtil;
import com.wm.data.ISMemDataImpl;
assertTrue(ir.hasIntercepted());
IDataCursor pc = pipeline.getCursor();
assertEquals(2, IDataUtil.size(pc));
assertEquals("avalue", IDataUtil.getString(pc, "akey"));
assertEquals("bvalue", IDataUtil.getString(pc, "bkey"));
}
@Test
public void shouldNotChange() throws IOException {
IData pipeline = getIData(new String[][]{{"bkey", "bvalue"}});
FlowPosition flowPosition = Mockito.mock(FlowPosition.class);
InterceptResult ir = new CannedResponseInterceptor((IData)null).intercept(flowPosition , pipeline);
assertTrue(ir.hasIntercepted());
IDataCursor pc = pipeline.getCursor();
assertEquals(1, IDataUtil.size(pc));
pc.destroy();
}
private IData getIData(String[][] data) {
IData idata = new ISMemDataImpl();
IDataCursor idc = idata.getCursor();
for (String[] kv : data) {
IDataUtil.put(idc, kv[0], kv[1]);
}
idc.destroy();
return idata;
}
@Test
public void shouldReturnSequential() { | CannedResponseInterceptor cri = new CannedResponseInterceptor(ResponseSequence.SEQUENTIAL, getIData(new String[][]{{"akey", "avalue"}}), getIData(new String[][]{{"bkey", "bvalue"}}), getIData(new String[][]{{"ckey", "cvalue"}})); |
wmaop/wm-aop | src/main/java/org/wmaop/aop/assertion/AssertionInterceptor.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/Interceptor.java
// public interface Interceptor {
//
// InterceptResult intercept(FlowPosition flowPosition, IData idata);
//
// int getInvokeCount();
//
// String getName();
//
// Map<String, Object> toMap();
//
// }
| import java.util.HashMap;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.aop.interceptor.Interceptor;
import com.wm.data.IData; | package org.wmaop.aop.assertion;
/**
* Default assertion. Counts the invokes and registers if one
* has asserted
*/
public class AssertionInterceptor implements Interceptor, Assertable {
private final String assertionName;
private int invokeCount = 0;
private boolean asserted;
public AssertionInterceptor(String assertionName) {
this.assertionName = assertionName;
}
public boolean performAssert(IData idata) {
return true;
}
public void reset() {
invokeCount = 0;
asserted = false;
}
@Override | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/Interceptor.java
// public interface Interceptor {
//
// InterceptResult intercept(FlowPosition flowPosition, IData idata);
//
// int getInvokeCount();
//
// String getName();
//
// Map<String, Object> toMap();
//
// }
// Path: src/main/java/org/wmaop/aop/assertion/AssertionInterceptor.java
import java.util.HashMap;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.aop.interceptor.Interceptor;
import com.wm.data.IData;
package org.wmaop.aop.assertion;
/**
* Default assertion. Counts the invokes and registers if one
* has asserted
*/
public class AssertionInterceptor implements Interceptor, Assertable {
private final String assertionName;
private int invokeCount = 0;
private boolean asserted;
public AssertionInterceptor(String assertionName) {
this.assertionName = assertionName;
}
public boolean performAssert(IData idata) {
return true;
}
public void reset() {
invokeCount = 0;
asserted = false;
}
@Override | public final InterceptResult intercept(FlowPosition flowPosition, IData idata) { |
wmaop/wm-aop | src/main/java/org/wmaop/aop/assertion/AssertionInterceptor.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/Interceptor.java
// public interface Interceptor {
//
// InterceptResult intercept(FlowPosition flowPosition, IData idata);
//
// int getInvokeCount();
//
// String getName();
//
// Map<String, Object> toMap();
//
// }
| import java.util.HashMap;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.aop.interceptor.Interceptor;
import com.wm.data.IData; | package org.wmaop.aop.assertion;
/**
* Default assertion. Counts the invokes and registers if one
* has asserted
*/
public class AssertionInterceptor implements Interceptor, Assertable {
private final String assertionName;
private int invokeCount = 0;
private boolean asserted;
public AssertionInterceptor(String assertionName) {
this.assertionName = assertionName;
}
public boolean performAssert(IData idata) {
return true;
}
public void reset() {
invokeCount = 0;
asserted = false;
}
@Override | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/Interceptor.java
// public interface Interceptor {
//
// InterceptResult intercept(FlowPosition flowPosition, IData idata);
//
// int getInvokeCount();
//
// String getName();
//
// Map<String, Object> toMap();
//
// }
// Path: src/main/java/org/wmaop/aop/assertion/AssertionInterceptor.java
import java.util.HashMap;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.aop.interceptor.Interceptor;
import com.wm.data.IData;
package org.wmaop.aop.assertion;
/**
* Default assertion. Counts the invokes and registers if one
* has asserted
*/
public class AssertionInterceptor implements Interceptor, Assertable {
private final String assertionName;
private int invokeCount = 0;
private boolean asserted;
public AssertionInterceptor(String assertionName) {
this.assertionName = assertionName;
}
public boolean performAssert(IData idata) {
return true;
}
public void reset() {
invokeCount = 0;
asserted = false;
}
@Override | public final InterceptResult intercept(FlowPosition flowPosition, IData idata) { |
wmaop/wm-aop | src/test/java/org/wmaop/aop/matcher/jexl/JexlIDataMatcherTest.java | // Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
| import static org.junit.Assert.*;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.wmaop.aop.matcher.MatchResult;
import com.wm.data.IData;
import com.wm.data.IDataCursor;
import com.wm.data.IDataFactory;
import com.wm.data.IDataUtil;
| package org.wmaop.aop.matcher.jexl;
public class JexlIDataMatcherTest {
@Test
public void shouldHandleMultipleExpressions() {
Map<String, String> exprs = new HashMap<>();
exprs.put("expr1", "foo == 'a'");
exprs.put("expr2", "foo == 'b'");
JexlIDataMatcher jidm = new JexlIDataMatcher(exprs);
IData idata = IDataFactory.create();
IDataCursor idc = idata.getCursor();
IDataUtil.put(idc, "foo", "x");
assertFalse(jidm.match(idata).isMatch());
IDataUtil.put(idc, "foo", "a");
| // Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
// Path: src/test/java/org/wmaop/aop/matcher/jexl/JexlIDataMatcherTest.java
import static org.junit.Assert.*;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.wmaop.aop.matcher.MatchResult;
import com.wm.data.IData;
import com.wm.data.IDataCursor;
import com.wm.data.IDataFactory;
import com.wm.data.IDataUtil;
package org.wmaop.aop.matcher.jexl;
public class JexlIDataMatcherTest {
@Test
public void shouldHandleMultipleExpressions() {
Map<String, String> exprs = new HashMap<>();
exprs.put("expr1", "foo == 'a'");
exprs.put("expr2", "foo == 'b'");
JexlIDataMatcher jidm = new JexlIDataMatcher(exprs);
IData idata = IDataFactory.create();
IDataCursor idc = idata.getCursor();
IDataUtil.put(idc, "foo", "x");
assertFalse(jidm.match(idata).isMatch());
IDataUtil.put(idc, "foo", "a");
| MatchResult m = jidm.match(idata);
|
wmaop/wm-aop | src/main/java/org/wmaop/aop/advice/remit/SessionRemit.java | // Path: src/main/java/org/wmaop/aop/advice/Scope.java
// public enum Scope {
// ALL, GLOBAL, SESSION, USER;
// }
//
// Path: src/main/java/org/wmaop/aop/advice/Scope.java
// public enum Scope {
// ALL, GLOBAL, SESSION, USER;
// }
| import static org.wmaop.aop.advice.Scope.*;
import org.wmaop.aop.advice.Scope;
import com.wm.app.b2b.server.InvokeState;
import com.wm.app.b2b.server.Session; | package org.wmaop.aop.advice.remit;
public class SessionRemit implements Remit {
public static final String NO_SESSION = "NoSession";
private final String associatedSessionId;
public SessionRemit() {
associatedSessionId = getSessionID();
}
public SessionRemit(String associatedSessionId) {
this.associatedSessionId = associatedSessionId;
}
@Override
public boolean isApplicable() {
return getSessionID().equals(associatedSessionId);
}
@Override | // Path: src/main/java/org/wmaop/aop/advice/Scope.java
// public enum Scope {
// ALL, GLOBAL, SESSION, USER;
// }
//
// Path: src/main/java/org/wmaop/aop/advice/Scope.java
// public enum Scope {
// ALL, GLOBAL, SESSION, USER;
// }
// Path: src/main/java/org/wmaop/aop/advice/remit/SessionRemit.java
import static org.wmaop.aop.advice.Scope.*;
import org.wmaop.aop.advice.Scope;
import com.wm.app.b2b.server.InvokeState;
import com.wm.app.b2b.server.Session;
package org.wmaop.aop.advice.remit;
public class SessionRemit implements Remit {
public static final String NO_SESSION = "NoSession";
private final String associatedSessionId;
public SessionRemit() {
associatedSessionId = getSessionID();
}
public SessionRemit(String associatedSessionId) {
this.associatedSessionId = associatedSessionId;
}
@Override
public boolean isApplicable() {
return getSessionID().equals(associatedSessionId);
}
@Override | public boolean isApplicable(Scope scope) { |
wmaop/wm-aop | src/main/java/org/wmaop/aop/advice/remit/GlobalRemit.java | // Path: src/main/java/org/wmaop/aop/advice/Scope.java
// public enum Scope {
// ALL, GLOBAL, SESSION, USER;
// }
//
// Path: src/main/java/org/wmaop/aop/advice/Scope.java
// public enum Scope {
// ALL, GLOBAL, SESSION, USER;
// }
| import org.wmaop.aop.advice.Scope;
import static org.wmaop.aop.advice.Scope.*;
| package org.wmaop.aop.advice.remit;
public final class GlobalRemit implements Remit {
@Override
public final boolean isApplicable() {
return true;
}
@Override
| // Path: src/main/java/org/wmaop/aop/advice/Scope.java
// public enum Scope {
// ALL, GLOBAL, SESSION, USER;
// }
//
// Path: src/main/java/org/wmaop/aop/advice/Scope.java
// public enum Scope {
// ALL, GLOBAL, SESSION, USER;
// }
// Path: src/main/java/org/wmaop/aop/advice/remit/GlobalRemit.java
import org.wmaop.aop.advice.Scope;
import static org.wmaop.aop.advice.Scope.*;
package org.wmaop.aop.advice.remit;
public final class GlobalRemit implements Remit {
@Override
public final boolean isApplicable() {
return true;
}
@Override
| public boolean isApplicable(Scope scope) {
|
wmaop/wm-aop | src/test/java/org/wmaop/interceptor/mock/exception/ExceptionInterceptorTest.java | // Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
| import static org.junit.Assert.*;
import org.junit.Test;
import org.wmaop.aop.interceptor.InterceptResult; | package org.wmaop.interceptor.mock.exception;
public class ExceptionInterceptorTest {
private static final String RUNTIME_EXCEPTION = "java.lang.RuntimeException";
@Test
public void shouldHandleExceptionInstance() throws Exception {
Exception exception = new Exception();
ExceptionInterceptor ei = new ExceptionInterceptor(exception);
| // Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
// Path: src/test/java/org/wmaop/interceptor/mock/exception/ExceptionInterceptorTest.java
import static org.junit.Assert.*;
import org.junit.Test;
import org.wmaop.aop.interceptor.InterceptResult;
package org.wmaop.interceptor.mock.exception;
public class ExceptionInterceptorTest {
private static final String RUNTIME_EXCEPTION = "java.lang.RuntimeException";
@Test
public void shouldHandleExceptionInstance() throws Exception {
Exception exception = new Exception();
ExceptionInterceptor ei = new ExceptionInterceptor(exception);
| InterceptResult ir = ei.intercept(null, null); |
wmaop/wm-aop | src/test/java/org/wmaop/aop/matcher/jexl/JexlServiceNameMatcherTest.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint; | package org.wmaop.aop.matcher.jexl;
public class JexlServiceNameMatcherTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void shouldMatch() {
JexlServiceNameMatcher jsnm = new JexlServiceNameMatcher("alpha", "serviceName == 'foo'"); | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
// Path: src/test/java/org/wmaop/aop/matcher/jexl/JexlServiceNameMatcherTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
package org.wmaop.aop.matcher.jexl;
public class JexlServiceNameMatcherTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void shouldMatch() {
JexlServiceNameMatcher jsnm = new JexlServiceNameMatcher("alpha", "serviceName == 'foo'"); | FlowPosition flowPosition = new FlowPosition(InterceptPoint.INVOKE, "foo"); |
wmaop/wm-aop | src/test/java/org/wmaop/aop/matcher/jexl/JexlServiceNameMatcherTest.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint; | package org.wmaop.aop.matcher.jexl;
public class JexlServiceNameMatcherTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void shouldMatch() {
JexlServiceNameMatcher jsnm = new JexlServiceNameMatcher("alpha", "serviceName == 'foo'"); | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
// Path: src/test/java/org/wmaop/aop/matcher/jexl/JexlServiceNameMatcherTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
package org.wmaop.aop.matcher.jexl;
public class JexlServiceNameMatcherTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void shouldMatch() {
JexlServiceNameMatcher jsnm = new JexlServiceNameMatcher("alpha", "serviceName == 'foo'"); | FlowPosition flowPosition = new FlowPosition(InterceptPoint.INVOKE, "foo"); |
wmaop/wm-aop | src/main/java/org/wmaop/aop/matcher/CallingServicePositionMatcher.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
| import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.util.logger.Logger;
import com.wm.app.b2b.server.InvokeState;
import com.wm.lang.ns.NSService;
| package org.wmaop.aop.matcher;
public class CallingServicePositionMatcher implements FlowPositionMatcher {
private final String serviceName;
private final MatchResult matchTrue;
private final String serviceNamespacePrefix;
private final String id;
private static final Logger logger = Logger.getLogger(CallingServicePositionMatcher.class);
public CallingServicePositionMatcher(String id, String serviceName, String serviceNamespacePrefix) {
this.serviceName = serviceName;
this.id = id;
matchTrue = new MatchResult(true, id);
this.serviceNamespacePrefix = serviceNamespacePrefix;
}
@Override
| // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
// Path: src/main/java/org/wmaop/aop/matcher/CallingServicePositionMatcher.java
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.util.logger.Logger;
import com.wm.app.b2b.server.InvokeState;
import com.wm.lang.ns.NSService;
package org.wmaop.aop.matcher;
public class CallingServicePositionMatcher implements FlowPositionMatcher {
private final String serviceName;
private final MatchResult matchTrue;
private final String serviceNamespacePrefix;
private final String id;
private static final Logger logger = Logger.getLogger(CallingServicePositionMatcher.class);
public CallingServicePositionMatcher(String id, String serviceName, String serviceNamespacePrefix) {
this.serviceName = serviceName;
this.id = id;
matchTrue = new MatchResult(true, id);
this.serviceNamespacePrefix = serviceNamespacePrefix;
}
@Override
| public MatchResult match(FlowPosition obj) {
|
wmaop/wm-aop | src/main/java/org/wmaop/interceptor/mock/canned/CannedResponseInterceptor.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/interceptor/BaseInterceptor.java
// public abstract class BaseInterceptor implements Interceptor {
//
// public static final String MAP_INVOKE_COUNT = "invokeCount";
// public static final String MAP_NAME = "name";
// public static final String MAP_TYPE = "type";
//
// protected final String name;
// protected int invokeCount = 0;
//
// protected BaseInterceptor(String name) {
// this.name = name;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put(MAP_NAME, name);
// am.put(MAP_INVOKE_COUNT, invokeCount);
// addMap(am);
// return am;
// }
//
// protected abstract void addMap(Map<String, Object> am);
//
// }
| import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.interceptor.BaseInterceptor;
import com.wm.data.IData;
import com.wm.data.IDataUtil;
import com.wm.util.coder.IDataXMLCoder; | public CannedResponseInterceptor(String idataXml) throws IOException {
this(new IDataXMLCoder().decodeFromBytes(idataXml.getBytes()));
}
public CannedResponseInterceptor(ResponseSequence seq, List<String> list) throws IOException {
super(CANNED_RESPONSE_PREFIX);
sequence = seq;
cannedIdata = new ArrayList<>();
for (String idataXml : list) {
cannedIdata.add(new IDataXMLCoder().decodeFromBytes(idataXml.getBytes()));
}
}
public CannedResponseInterceptor(InputStream idataXmlStream) throws IOException {
this(new IDataXMLCoder().decode(idataXmlStream));
}
public CannedResponseInterceptor(IData idata) {
super(CANNED_RESPONSE_PREFIX);
cannedIdata = Arrays.asList(idata);
sequence = ResponseSequence.SEQUENTIAL;
}
public CannedResponseInterceptor(ResponseSequence seq, IData... idata) {
super(CANNED_RESPONSE_PREFIX);
cannedIdata = Arrays.asList(idata);
sequence = seq;
}
@Override | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/interceptor/BaseInterceptor.java
// public abstract class BaseInterceptor implements Interceptor {
//
// public static final String MAP_INVOKE_COUNT = "invokeCount";
// public static final String MAP_NAME = "name";
// public static final String MAP_TYPE = "type";
//
// protected final String name;
// protected int invokeCount = 0;
//
// protected BaseInterceptor(String name) {
// this.name = name;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put(MAP_NAME, name);
// am.put(MAP_INVOKE_COUNT, invokeCount);
// addMap(am);
// return am;
// }
//
// protected abstract void addMap(Map<String, Object> am);
//
// }
// Path: src/main/java/org/wmaop/interceptor/mock/canned/CannedResponseInterceptor.java
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.interceptor.BaseInterceptor;
import com.wm.data.IData;
import com.wm.data.IDataUtil;
import com.wm.util.coder.IDataXMLCoder;
public CannedResponseInterceptor(String idataXml) throws IOException {
this(new IDataXMLCoder().decodeFromBytes(idataXml.getBytes()));
}
public CannedResponseInterceptor(ResponseSequence seq, List<String> list) throws IOException {
super(CANNED_RESPONSE_PREFIX);
sequence = seq;
cannedIdata = new ArrayList<>();
for (String idataXml : list) {
cannedIdata.add(new IDataXMLCoder().decodeFromBytes(idataXml.getBytes()));
}
}
public CannedResponseInterceptor(InputStream idataXmlStream) throws IOException {
this(new IDataXMLCoder().decode(idataXmlStream));
}
public CannedResponseInterceptor(IData idata) {
super(CANNED_RESPONSE_PREFIX);
cannedIdata = Arrays.asList(idata);
sequence = ResponseSequence.SEQUENTIAL;
}
public CannedResponseInterceptor(ResponseSequence seq, IData... idata) {
super(CANNED_RESPONSE_PREFIX);
cannedIdata = Arrays.asList(idata);
sequence = seq;
}
@Override | public InterceptResult intercept(FlowPosition flowPosition, IData pipeline) { |
wmaop/wm-aop | src/main/java/org/wmaop/interceptor/mock/canned/CannedResponseInterceptor.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/interceptor/BaseInterceptor.java
// public abstract class BaseInterceptor implements Interceptor {
//
// public static final String MAP_INVOKE_COUNT = "invokeCount";
// public static final String MAP_NAME = "name";
// public static final String MAP_TYPE = "type";
//
// protected final String name;
// protected int invokeCount = 0;
//
// protected BaseInterceptor(String name) {
// this.name = name;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put(MAP_NAME, name);
// am.put(MAP_INVOKE_COUNT, invokeCount);
// addMap(am);
// return am;
// }
//
// protected abstract void addMap(Map<String, Object> am);
//
// }
| import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.interceptor.BaseInterceptor;
import com.wm.data.IData;
import com.wm.data.IDataUtil;
import com.wm.util.coder.IDataXMLCoder; | public CannedResponseInterceptor(String idataXml) throws IOException {
this(new IDataXMLCoder().decodeFromBytes(idataXml.getBytes()));
}
public CannedResponseInterceptor(ResponseSequence seq, List<String> list) throws IOException {
super(CANNED_RESPONSE_PREFIX);
sequence = seq;
cannedIdata = new ArrayList<>();
for (String idataXml : list) {
cannedIdata.add(new IDataXMLCoder().decodeFromBytes(idataXml.getBytes()));
}
}
public CannedResponseInterceptor(InputStream idataXmlStream) throws IOException {
this(new IDataXMLCoder().decode(idataXmlStream));
}
public CannedResponseInterceptor(IData idata) {
super(CANNED_RESPONSE_PREFIX);
cannedIdata = Arrays.asList(idata);
sequence = ResponseSequence.SEQUENTIAL;
}
public CannedResponseInterceptor(ResponseSequence seq, IData... idata) {
super(CANNED_RESPONSE_PREFIX);
cannedIdata = Arrays.asList(idata);
sequence = seq;
}
@Override | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/interceptor/BaseInterceptor.java
// public abstract class BaseInterceptor implements Interceptor {
//
// public static final String MAP_INVOKE_COUNT = "invokeCount";
// public static final String MAP_NAME = "name";
// public static final String MAP_TYPE = "type";
//
// protected final String name;
// protected int invokeCount = 0;
//
// protected BaseInterceptor(String name) {
// this.name = name;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put(MAP_NAME, name);
// am.put(MAP_INVOKE_COUNT, invokeCount);
// addMap(am);
// return am;
// }
//
// protected abstract void addMap(Map<String, Object> am);
//
// }
// Path: src/main/java/org/wmaop/interceptor/mock/canned/CannedResponseInterceptor.java
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.interceptor.BaseInterceptor;
import com.wm.data.IData;
import com.wm.data.IDataUtil;
import com.wm.util.coder.IDataXMLCoder;
public CannedResponseInterceptor(String idataXml) throws IOException {
this(new IDataXMLCoder().decodeFromBytes(idataXml.getBytes()));
}
public CannedResponseInterceptor(ResponseSequence seq, List<String> list) throws IOException {
super(CANNED_RESPONSE_PREFIX);
sequence = seq;
cannedIdata = new ArrayList<>();
for (String idataXml : list) {
cannedIdata.add(new IDataXMLCoder().decodeFromBytes(idataXml.getBytes()));
}
}
public CannedResponseInterceptor(InputStream idataXmlStream) throws IOException {
this(new IDataXMLCoder().decode(idataXmlStream));
}
public CannedResponseInterceptor(IData idata) {
super(CANNED_RESPONSE_PREFIX);
cannedIdata = Arrays.asList(idata);
sequence = ResponseSequence.SEQUENTIAL;
}
public CannedResponseInterceptor(ResponseSequence seq, IData... idata) {
super(CANNED_RESPONSE_PREFIX);
cannedIdata = Arrays.asList(idata);
sequence = seq;
}
@Override | public InterceptResult intercept(FlowPosition flowPosition, IData pipeline) { |
wmaop/wm-aop | src/main/java/org/wmaop/aop/matcher/jexl/JexlIDataMatcher.java | // Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/Matcher.java
// public interface Matcher<T> {
// MatchResult match(T value);
//
// Map<String, Object> toMap();
// }
| import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.JexlExpression;
import org.apache.commons.jexl3.MapContext;
import org.wmaop.aop.matcher.MatchResult;
import org.wmaop.aop.matcher.Matcher;
import org.wmaop.util.jexl.IDataJexlContext;
import org.wmaop.util.jexl.JexlExpressionFactory;
import com.wm.data.IData; | package org.wmaop.aop.matcher.jexl;
public class JexlIDataMatcher implements Matcher<IData> {
private final Map<String, JexlExpression> expressions = new LinkedHashMap<>();
private final String expression;
public JexlIDataMatcher(String sid, String expression) {
createExpression(sid, expression);
this.expression = expression;
}
public JexlIDataMatcher(Map<String, String> exprs) {
for (Entry<String, String> expr : exprs.entrySet()) {
createExpression(expr.getKey(), expr.getValue());
}
expression = Arrays.toString(expressions.values().toArray());
}
@Override | // Path: src/main/java/org/wmaop/aop/matcher/MatchResult.java
// public class MatchResult {
//
// public static final MatchResult FALSE = new MatchResult(false, "undefined");
// public static final MatchResult TRUE = new MatchResult(true, "undefined");
//
// private final boolean isMatch;
// private final String id;
//
// public MatchResult(boolean result, String id) {
// this.id = id;
// isMatch = result;
// }
//
// public boolean isMatch() {
// return isMatch;
// }
//
// public String getId() {
// return id;
// }
//
// @Override
// public String toString() {
// return "MatchResult:"+isMatch+" for " + id;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/matcher/Matcher.java
// public interface Matcher<T> {
// MatchResult match(T value);
//
// Map<String, Object> toMap();
// }
// Path: src/main/java/org/wmaop/aop/matcher/jexl/JexlIDataMatcher.java
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.JexlExpression;
import org.apache.commons.jexl3.MapContext;
import org.wmaop.aop.matcher.MatchResult;
import org.wmaop.aop.matcher.Matcher;
import org.wmaop.util.jexl.IDataJexlContext;
import org.wmaop.util.jexl.JexlExpressionFactory;
import com.wm.data.IData;
package org.wmaop.aop.matcher.jexl;
public class JexlIDataMatcher implements Matcher<IData> {
private final Map<String, JexlExpression> expressions = new LinkedHashMap<>();
private final String expression;
public JexlIDataMatcher(String sid, String expression) {
createExpression(sid, expression);
this.expression = expression;
}
public JexlIDataMatcher(Map<String, String> exprs) {
for (Entry<String, String> expr : exprs.entrySet()) {
createExpression(expr.getKey(), expr.getValue());
}
expression = Arrays.toString(expressions.values().toArray());
}
@Override | public MatchResult match(IData idata) { |
wmaop/wm-aop | src/test/java/org/wmaop/aop/matcher/AlwaysTrueMatcherTest.java | // Path: src/main/java/org/wmaop/aop/matcher/AlwaysTrueMatcher.java
// public class AlwaysTrueMatcher<T> implements Matcher<T> {
//
// private final MatchResult result;
// private final String id;
//
// public AlwaysTrueMatcher(String id) {
// result = new MatchResult(true, id);
// this.id = id;
// }
//
// @Override
// public String toString() {
// return "AlwaysTrueMatcher[" + id + ']';
// }
//
// @Override
// public MatchResult match(Object value) {
// return result;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("id", id);
// am.put("type", "AlwaysTrueMatcher");
// return am;
// }
//
// }
| import static org.junit.Assert.*;
import org.junit.Test;
import org.wmaop.aop.matcher.AlwaysTrueMatcher; | package org.wmaop.aop.matcher;
public class AlwaysTrueMatcherTest {
@Test
public void shouldBeAlwaysTrue() { | // Path: src/main/java/org/wmaop/aop/matcher/AlwaysTrueMatcher.java
// public class AlwaysTrueMatcher<T> implements Matcher<T> {
//
// private final MatchResult result;
// private final String id;
//
// public AlwaysTrueMatcher(String id) {
// result = new MatchResult(true, id);
// this.id = id;
// }
//
// @Override
// public String toString() {
// return "AlwaysTrueMatcher[" + id + ']';
// }
//
// @Override
// public MatchResult match(Object value) {
// return result;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("id", id);
// am.put("type", "AlwaysTrueMatcher");
// return am;
// }
//
// }
// Path: src/test/java/org/wmaop/aop/matcher/AlwaysTrueMatcherTest.java
import static org.junit.Assert.*;
import org.junit.Test;
import org.wmaop.aop.matcher.AlwaysTrueMatcher;
package org.wmaop.aop.matcher;
public class AlwaysTrueMatcherTest {
@Test
public void shouldBeAlwaysTrue() { | AlwaysTrueMatcher<Object> atm = new AlwaysTrueMatcher<Object>("foo"); |
wmaop/wm-aop | src/main/java/org/wmaop/aop/matcher/FlowPositionMatcherImpl.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
| import java.util.HashMap;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
| package org.wmaop.aop.matcher;
public class FlowPositionMatcherImpl implements FlowPositionMatcher {
private final String serviceName;
private final MatchResult matchTrue;
private final String id;
public FlowPositionMatcherImpl(String id, String serviceName) {
this.serviceName = serviceName;
this.id = id;
matchTrue = new MatchResult(true, id);
}
@Override
| // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
// Path: src/main/java/org/wmaop/aop/matcher/FlowPositionMatcherImpl.java
import java.util.HashMap;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
package org.wmaop.aop.matcher;
public class FlowPositionMatcherImpl implements FlowPositionMatcher {
private final String serviceName;
private final MatchResult matchTrue;
private final String id;
public FlowPositionMatcherImpl(String id, String serviceName) {
this.serviceName = serviceName;
this.id = id;
matchTrue = new MatchResult(true, id);
}
@Override
| public MatchResult match(FlowPosition obj) {
|
wmaop/wm-aop | src/main/java/org/wmaop/interceptor/mock/restful/RestDelegatingInterceptor.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptionException.java
// public class InterceptionException extends RuntimeException {
//
// public InterceptionException(String message) {
// super(message);
// }
//
// public InterceptionException(Throwable cause) {
// super(cause);
// }
//
// public InterceptionException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/org/wmaop/interceptor/BaseInterceptor.java
// public abstract class BaseInterceptor implements Interceptor {
//
// public static final String MAP_INVOKE_COUNT = "invokeCount";
// public static final String MAP_NAME = "name";
// public static final String MAP_TYPE = "type";
//
// protected final String name;
// protected int invokeCount = 0;
//
// protected BaseInterceptor(String name) {
// this.name = name;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put(MAP_NAME, name);
// am.put(MAP_INVOKE_COUNT, invokeCount);
// addMap(am);
// return am;
// }
//
// protected abstract void addMap(Map<String, Object> am);
//
// }
| import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.aop.interceptor.InterceptionException;
import org.wmaop.interceptor.BaseInterceptor;
import com.wm.data.IData;
import com.wm.data.IDataUtil;
import com.wm.util.coder.IDataXMLCoder; | package org.wmaop.interceptor.mock.restful;
public class RestDelegatingInterceptor extends BaseInterceptor {
public static final String MAP_DESTINATION_URL = "destinationUrl";
public static final String APPLICATION_XML = "application/xml";
private final String destinationUrl;
private final String serviceName;
public RestDelegatingInterceptor(String serviceName, String destinationUrl) {
super("Restful:"+serviceName);
this.serviceName = serviceName;
this.destinationUrl = destinationUrl;
}
@Override | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptionException.java
// public class InterceptionException extends RuntimeException {
//
// public InterceptionException(String message) {
// super(message);
// }
//
// public InterceptionException(Throwable cause) {
// super(cause);
// }
//
// public InterceptionException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/org/wmaop/interceptor/BaseInterceptor.java
// public abstract class BaseInterceptor implements Interceptor {
//
// public static final String MAP_INVOKE_COUNT = "invokeCount";
// public static final String MAP_NAME = "name";
// public static final String MAP_TYPE = "type";
//
// protected final String name;
// protected int invokeCount = 0;
//
// protected BaseInterceptor(String name) {
// this.name = name;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put(MAP_NAME, name);
// am.put(MAP_INVOKE_COUNT, invokeCount);
// addMap(am);
// return am;
// }
//
// protected abstract void addMap(Map<String, Object> am);
//
// }
// Path: src/main/java/org/wmaop/interceptor/mock/restful/RestDelegatingInterceptor.java
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.aop.interceptor.InterceptionException;
import org.wmaop.interceptor.BaseInterceptor;
import com.wm.data.IData;
import com.wm.data.IDataUtil;
import com.wm.util.coder.IDataXMLCoder;
package org.wmaop.interceptor.mock.restful;
public class RestDelegatingInterceptor extends BaseInterceptor {
public static final String MAP_DESTINATION_URL = "destinationUrl";
public static final String APPLICATION_XML = "application/xml";
private final String destinationUrl;
private final String serviceName;
public RestDelegatingInterceptor(String serviceName, String destinationUrl) {
super("Restful:"+serviceName);
this.serviceName = serviceName;
this.destinationUrl = destinationUrl;
}
@Override | public InterceptResult intercept(FlowPosition flowPosition, IData idata) { |
wmaop/wm-aop | src/main/java/org/wmaop/interceptor/mock/restful/RestDelegatingInterceptor.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptionException.java
// public class InterceptionException extends RuntimeException {
//
// public InterceptionException(String message) {
// super(message);
// }
//
// public InterceptionException(Throwable cause) {
// super(cause);
// }
//
// public InterceptionException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/org/wmaop/interceptor/BaseInterceptor.java
// public abstract class BaseInterceptor implements Interceptor {
//
// public static final String MAP_INVOKE_COUNT = "invokeCount";
// public static final String MAP_NAME = "name";
// public static final String MAP_TYPE = "type";
//
// protected final String name;
// protected int invokeCount = 0;
//
// protected BaseInterceptor(String name) {
// this.name = name;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put(MAP_NAME, name);
// am.put(MAP_INVOKE_COUNT, invokeCount);
// addMap(am);
// return am;
// }
//
// protected abstract void addMap(Map<String, Object> am);
//
// }
| import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.aop.interceptor.InterceptionException;
import org.wmaop.interceptor.BaseInterceptor;
import com.wm.data.IData;
import com.wm.data.IDataUtil;
import com.wm.util.coder.IDataXMLCoder; | package org.wmaop.interceptor.mock.restful;
public class RestDelegatingInterceptor extends BaseInterceptor {
public static final String MAP_DESTINATION_URL = "destinationUrl";
public static final String APPLICATION_XML = "application/xml";
private final String destinationUrl;
private final String serviceName;
public RestDelegatingInterceptor(String serviceName, String destinationUrl) {
super("Restful:"+serviceName);
this.serviceName = serviceName;
this.destinationUrl = destinationUrl;
}
@Override | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptionException.java
// public class InterceptionException extends RuntimeException {
//
// public InterceptionException(String message) {
// super(message);
// }
//
// public InterceptionException(Throwable cause) {
// super(cause);
// }
//
// public InterceptionException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/org/wmaop/interceptor/BaseInterceptor.java
// public abstract class BaseInterceptor implements Interceptor {
//
// public static final String MAP_INVOKE_COUNT = "invokeCount";
// public static final String MAP_NAME = "name";
// public static final String MAP_TYPE = "type";
//
// protected final String name;
// protected int invokeCount = 0;
//
// protected BaseInterceptor(String name) {
// this.name = name;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put(MAP_NAME, name);
// am.put(MAP_INVOKE_COUNT, invokeCount);
// addMap(am);
// return am;
// }
//
// protected abstract void addMap(Map<String, Object> am);
//
// }
// Path: src/main/java/org/wmaop/interceptor/mock/restful/RestDelegatingInterceptor.java
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.aop.interceptor.InterceptionException;
import org.wmaop.interceptor.BaseInterceptor;
import com.wm.data.IData;
import com.wm.data.IDataUtil;
import com.wm.util.coder.IDataXMLCoder;
package org.wmaop.interceptor.mock.restful;
public class RestDelegatingInterceptor extends BaseInterceptor {
public static final String MAP_DESTINATION_URL = "destinationUrl";
public static final String APPLICATION_XML = "application/xml";
private final String destinationUrl;
private final String serviceName;
public RestDelegatingInterceptor(String serviceName, String destinationUrl) {
super("Restful:"+serviceName);
this.serviceName = serviceName;
this.destinationUrl = destinationUrl;
}
@Override | public InterceptResult intercept(FlowPosition flowPosition, IData idata) { |
wmaop/wm-aop | src/main/java/org/wmaop/interceptor/mock/restful/RestDelegatingInterceptor.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptionException.java
// public class InterceptionException extends RuntimeException {
//
// public InterceptionException(String message) {
// super(message);
// }
//
// public InterceptionException(Throwable cause) {
// super(cause);
// }
//
// public InterceptionException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/org/wmaop/interceptor/BaseInterceptor.java
// public abstract class BaseInterceptor implements Interceptor {
//
// public static final String MAP_INVOKE_COUNT = "invokeCount";
// public static final String MAP_NAME = "name";
// public static final String MAP_TYPE = "type";
//
// protected final String name;
// protected int invokeCount = 0;
//
// protected BaseInterceptor(String name) {
// this.name = name;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put(MAP_NAME, name);
// am.put(MAP_INVOKE_COUNT, invokeCount);
// addMap(am);
// return am;
// }
//
// protected abstract void addMap(Map<String, Object> am);
//
// }
| import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.aop.interceptor.InterceptionException;
import org.wmaop.interceptor.BaseInterceptor;
import com.wm.data.IData;
import com.wm.data.IDataUtil;
import com.wm.util.coder.IDataXMLCoder; | @Override
public InterceptResult intercept(FlowPosition flowPosition, IData idata) {
invokeCount++;
sendPost(idata);
return InterceptResult.TRUE;
}
@Override
public String getName() {
return serviceName;
}
private void sendPost(IData idata) {
try {
URL url = new URL(destinationUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", APPLICATION_XML);
IDataXMLCoder idxc = new IDataXMLCoder();
OutputStream os = conn.getOutputStream();
idxc.encode(os, idata);
os.flush();
IDataUtil.merge(idxc.decode(conn.getInputStream()), idata);
conn.disconnect();
} catch (IOException e) { | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptionException.java
// public class InterceptionException extends RuntimeException {
//
// public InterceptionException(String message) {
// super(message);
// }
//
// public InterceptionException(Throwable cause) {
// super(cause);
// }
//
// public InterceptionException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/org/wmaop/interceptor/BaseInterceptor.java
// public abstract class BaseInterceptor implements Interceptor {
//
// public static final String MAP_INVOKE_COUNT = "invokeCount";
// public static final String MAP_NAME = "name";
// public static final String MAP_TYPE = "type";
//
// protected final String name;
// protected int invokeCount = 0;
//
// protected BaseInterceptor(String name) {
// this.name = name;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put(MAP_NAME, name);
// am.put(MAP_INVOKE_COUNT, invokeCount);
// addMap(am);
// return am;
// }
//
// protected abstract void addMap(Map<String, Object> am);
//
// }
// Path: src/main/java/org/wmaop/interceptor/mock/restful/RestDelegatingInterceptor.java
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.aop.interceptor.InterceptionException;
import org.wmaop.interceptor.BaseInterceptor;
import com.wm.data.IData;
import com.wm.data.IDataUtil;
import com.wm.util.coder.IDataXMLCoder;
@Override
public InterceptResult intercept(FlowPosition flowPosition, IData idata) {
invokeCount++;
sendPost(idata);
return InterceptResult.TRUE;
}
@Override
public String getName() {
return serviceName;
}
private void sendPost(IData idata) {
try {
URL url = new URL(destinationUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", APPLICATION_XML);
IDataXMLCoder idxc = new IDataXMLCoder();
OutputStream os = conn.getOutputStream();
idxc.encode(os, idata);
os.flush();
IDataUtil.merge(idxc.decode(conn.getInputStream()), idata);
conn.disconnect();
} catch (IOException e) { | throw new InterceptionException("Error while forwarding request", e); |
wmaop/wm-aop | src/test/java/org/wmaop/aop/stub/StubLifecycleObserverTest.java | // Path: src/main/java/org/wmaop/aop/advice/Advice.java
// public class Advice {
//
// private final PointCut pointCut;
// private final Interceptor interceptor;
// private final String id;
// private AdviceState adviceState = AdviceState.NEW;
// private final Remit remit;
//
// public Advice(String id, Remit remit, PointCut pointCut, Interceptor interceptor) {
// this.pointCut = pointCut;
// this.interceptor = interceptor;
// this.id = id;
// this.remit = remit;
// }
//
// public Remit getRemit() {
// return remit;
// }
//
// public PointCut getPointCut() {
// return pointCut;
// }
//
// public boolean isApplicable(FlowPosition pipelinePosition, IData idata){
// return pointCut.isApplicable(pipelinePosition, idata) && remit.isApplicable();
// }
//
// public Interceptor getInterceptor() {
// return interceptor;
// }
//
// public String getId() {
// return id;
// }
//
// public AdviceState getAdviceState() {
// return adviceState;
// }
//
// public void setAdviceState(AdviceState adviceState) {
// this.adviceState = adviceState;
// }
//
// @Override
// public String toString() {
// return id + ' ' + adviceState + ' ' + pointCut + ' ' + interceptor + ' ' + pointCut.getInterceptPoint() + ' ' + remit;
// }
//
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("state", adviceState.toString());
// am.put("adviceId", id);
// am.put("pointcut", pointCut.toMap());
// am.put("interceptor", interceptor.toMap());
// am.put("remit", remit.toString());
// return am;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Advice other = (Advice) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/advice/AdviceState.java
// public enum AdviceState {
//
// NEW, ENABLED, DISABLED, DISPOSED;
// }
//
// Path: src/main/java/org/wmaop/aop/assertion/AssertionInterceptor.java
// public class AssertionInterceptor implements Interceptor, Assertable {
//
// private final String assertionName;
// private int invokeCount = 0;
// private boolean asserted;
//
// public AssertionInterceptor(String assertionName) {
// this.assertionName = assertionName;
// }
//
// public boolean performAssert(IData idata) {
// return true;
// }
//
// public void reset() {
// invokeCount = 0;
// asserted = false;
// }
//
// @Override
// public final InterceptResult intercept(FlowPosition flowPosition, IData idata) {
// invokeCount++;
// if (performAssert(idata)) {
// asserted = true;
// }
// return InterceptResult.FALSE;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// public boolean hasAsserted() {
// return asserted;
// }
//
// @Override
// public String getName() {
// return assertionName;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("assertionName", assertionName);
// am.put("invokeCount", invokeCount);
// am.put("asserted", Boolean.toString(asserted));
// return am;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/Interceptor.java
// public interface Interceptor {
//
// InterceptResult intercept(FlowPosition flowPosition, IData idata);
//
// int getInvokeCount();
//
// String getName();
//
// Map<String, Object> toMap();
//
// }
| import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.wmaop.aop.advice.Advice;
import org.wmaop.aop.advice.AdviceState;
import org.wmaop.aop.assertion.AssertionInterceptor;
import org.wmaop.aop.interceptor.Interceptor; | package org.wmaop.aop.stub;
public class StubLifecycleObserverTest {
private StubManager stubManager; | // Path: src/main/java/org/wmaop/aop/advice/Advice.java
// public class Advice {
//
// private final PointCut pointCut;
// private final Interceptor interceptor;
// private final String id;
// private AdviceState adviceState = AdviceState.NEW;
// private final Remit remit;
//
// public Advice(String id, Remit remit, PointCut pointCut, Interceptor interceptor) {
// this.pointCut = pointCut;
// this.interceptor = interceptor;
// this.id = id;
// this.remit = remit;
// }
//
// public Remit getRemit() {
// return remit;
// }
//
// public PointCut getPointCut() {
// return pointCut;
// }
//
// public boolean isApplicable(FlowPosition pipelinePosition, IData idata){
// return pointCut.isApplicable(pipelinePosition, idata) && remit.isApplicable();
// }
//
// public Interceptor getInterceptor() {
// return interceptor;
// }
//
// public String getId() {
// return id;
// }
//
// public AdviceState getAdviceState() {
// return adviceState;
// }
//
// public void setAdviceState(AdviceState adviceState) {
// this.adviceState = adviceState;
// }
//
// @Override
// public String toString() {
// return id + ' ' + adviceState + ' ' + pointCut + ' ' + interceptor + ' ' + pointCut.getInterceptPoint() + ' ' + remit;
// }
//
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("state", adviceState.toString());
// am.put("adviceId", id);
// am.put("pointcut", pointCut.toMap());
// am.put("interceptor", interceptor.toMap());
// am.put("remit", remit.toString());
// return am;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Advice other = (Advice) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/advice/AdviceState.java
// public enum AdviceState {
//
// NEW, ENABLED, DISABLED, DISPOSED;
// }
//
// Path: src/main/java/org/wmaop/aop/assertion/AssertionInterceptor.java
// public class AssertionInterceptor implements Interceptor, Assertable {
//
// private final String assertionName;
// private int invokeCount = 0;
// private boolean asserted;
//
// public AssertionInterceptor(String assertionName) {
// this.assertionName = assertionName;
// }
//
// public boolean performAssert(IData idata) {
// return true;
// }
//
// public void reset() {
// invokeCount = 0;
// asserted = false;
// }
//
// @Override
// public final InterceptResult intercept(FlowPosition flowPosition, IData idata) {
// invokeCount++;
// if (performAssert(idata)) {
// asserted = true;
// }
// return InterceptResult.FALSE;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// public boolean hasAsserted() {
// return asserted;
// }
//
// @Override
// public String getName() {
// return assertionName;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("assertionName", assertionName);
// am.put("invokeCount", invokeCount);
// am.put("asserted", Boolean.toString(asserted));
// return am;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/Interceptor.java
// public interface Interceptor {
//
// InterceptResult intercept(FlowPosition flowPosition, IData idata);
//
// int getInvokeCount();
//
// String getName();
//
// Map<String, Object> toMap();
//
// }
// Path: src/test/java/org/wmaop/aop/stub/StubLifecycleObserverTest.java
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.wmaop.aop.advice.Advice;
import org.wmaop.aop.advice.AdviceState;
import org.wmaop.aop.assertion.AssertionInterceptor;
import org.wmaop.aop.interceptor.Interceptor;
package org.wmaop.aop.stub;
public class StubLifecycleObserverTest {
private StubManager stubManager; | private Advice advice; |
wmaop/wm-aop | src/test/java/org/wmaop/aop/stub/StubLifecycleObserverTest.java | // Path: src/main/java/org/wmaop/aop/advice/Advice.java
// public class Advice {
//
// private final PointCut pointCut;
// private final Interceptor interceptor;
// private final String id;
// private AdviceState adviceState = AdviceState.NEW;
// private final Remit remit;
//
// public Advice(String id, Remit remit, PointCut pointCut, Interceptor interceptor) {
// this.pointCut = pointCut;
// this.interceptor = interceptor;
// this.id = id;
// this.remit = remit;
// }
//
// public Remit getRemit() {
// return remit;
// }
//
// public PointCut getPointCut() {
// return pointCut;
// }
//
// public boolean isApplicable(FlowPosition pipelinePosition, IData idata){
// return pointCut.isApplicable(pipelinePosition, idata) && remit.isApplicable();
// }
//
// public Interceptor getInterceptor() {
// return interceptor;
// }
//
// public String getId() {
// return id;
// }
//
// public AdviceState getAdviceState() {
// return adviceState;
// }
//
// public void setAdviceState(AdviceState adviceState) {
// this.adviceState = adviceState;
// }
//
// @Override
// public String toString() {
// return id + ' ' + adviceState + ' ' + pointCut + ' ' + interceptor + ' ' + pointCut.getInterceptPoint() + ' ' + remit;
// }
//
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("state", adviceState.toString());
// am.put("adviceId", id);
// am.put("pointcut", pointCut.toMap());
// am.put("interceptor", interceptor.toMap());
// am.put("remit", remit.toString());
// return am;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Advice other = (Advice) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/advice/AdviceState.java
// public enum AdviceState {
//
// NEW, ENABLED, DISABLED, DISPOSED;
// }
//
// Path: src/main/java/org/wmaop/aop/assertion/AssertionInterceptor.java
// public class AssertionInterceptor implements Interceptor, Assertable {
//
// private final String assertionName;
// private int invokeCount = 0;
// private boolean asserted;
//
// public AssertionInterceptor(String assertionName) {
// this.assertionName = assertionName;
// }
//
// public boolean performAssert(IData idata) {
// return true;
// }
//
// public void reset() {
// invokeCount = 0;
// asserted = false;
// }
//
// @Override
// public final InterceptResult intercept(FlowPosition flowPosition, IData idata) {
// invokeCount++;
// if (performAssert(idata)) {
// asserted = true;
// }
// return InterceptResult.FALSE;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// public boolean hasAsserted() {
// return asserted;
// }
//
// @Override
// public String getName() {
// return assertionName;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("assertionName", assertionName);
// am.put("invokeCount", invokeCount);
// am.put("asserted", Boolean.toString(asserted));
// return am;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/Interceptor.java
// public interface Interceptor {
//
// InterceptResult intercept(FlowPosition flowPosition, IData idata);
//
// int getInvokeCount();
//
// String getName();
//
// Map<String, Object> toMap();
//
// }
| import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.wmaop.aop.advice.Advice;
import org.wmaop.aop.advice.AdviceState;
import org.wmaop.aop.assertion.AssertionInterceptor;
import org.wmaop.aop.interceptor.Interceptor; | package org.wmaop.aop.stub;
public class StubLifecycleObserverTest {
private StubManager stubManager;
private Advice advice;
@Before
public void setup() {
stubManager = mock(StubManager.class);
advice = mock(Advice.class);
}
@Test
public void shouldNotAttemptStubUnregister() {
StubLifecycleObserver slo = new StubLifecycleObserver(stubManager); | // Path: src/main/java/org/wmaop/aop/advice/Advice.java
// public class Advice {
//
// private final PointCut pointCut;
// private final Interceptor interceptor;
// private final String id;
// private AdviceState adviceState = AdviceState.NEW;
// private final Remit remit;
//
// public Advice(String id, Remit remit, PointCut pointCut, Interceptor interceptor) {
// this.pointCut = pointCut;
// this.interceptor = interceptor;
// this.id = id;
// this.remit = remit;
// }
//
// public Remit getRemit() {
// return remit;
// }
//
// public PointCut getPointCut() {
// return pointCut;
// }
//
// public boolean isApplicable(FlowPosition pipelinePosition, IData idata){
// return pointCut.isApplicable(pipelinePosition, idata) && remit.isApplicable();
// }
//
// public Interceptor getInterceptor() {
// return interceptor;
// }
//
// public String getId() {
// return id;
// }
//
// public AdviceState getAdviceState() {
// return adviceState;
// }
//
// public void setAdviceState(AdviceState adviceState) {
// this.adviceState = adviceState;
// }
//
// @Override
// public String toString() {
// return id + ' ' + adviceState + ' ' + pointCut + ' ' + interceptor + ' ' + pointCut.getInterceptPoint() + ' ' + remit;
// }
//
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("state", adviceState.toString());
// am.put("adviceId", id);
// am.put("pointcut", pointCut.toMap());
// am.put("interceptor", interceptor.toMap());
// am.put("remit", remit.toString());
// return am;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Advice other = (Advice) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/advice/AdviceState.java
// public enum AdviceState {
//
// NEW, ENABLED, DISABLED, DISPOSED;
// }
//
// Path: src/main/java/org/wmaop/aop/assertion/AssertionInterceptor.java
// public class AssertionInterceptor implements Interceptor, Assertable {
//
// private final String assertionName;
// private int invokeCount = 0;
// private boolean asserted;
//
// public AssertionInterceptor(String assertionName) {
// this.assertionName = assertionName;
// }
//
// public boolean performAssert(IData idata) {
// return true;
// }
//
// public void reset() {
// invokeCount = 0;
// asserted = false;
// }
//
// @Override
// public final InterceptResult intercept(FlowPosition flowPosition, IData idata) {
// invokeCount++;
// if (performAssert(idata)) {
// asserted = true;
// }
// return InterceptResult.FALSE;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// public boolean hasAsserted() {
// return asserted;
// }
//
// @Override
// public String getName() {
// return assertionName;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("assertionName", assertionName);
// am.put("invokeCount", invokeCount);
// am.put("asserted", Boolean.toString(asserted));
// return am;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/Interceptor.java
// public interface Interceptor {
//
// InterceptResult intercept(FlowPosition flowPosition, IData idata);
//
// int getInvokeCount();
//
// String getName();
//
// Map<String, Object> toMap();
//
// }
// Path: src/test/java/org/wmaop/aop/stub/StubLifecycleObserverTest.java
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.wmaop.aop.advice.Advice;
import org.wmaop.aop.advice.AdviceState;
import org.wmaop.aop.assertion.AssertionInterceptor;
import org.wmaop.aop.interceptor.Interceptor;
package org.wmaop.aop.stub;
public class StubLifecycleObserverTest {
private StubManager stubManager;
private Advice advice;
@Before
public void setup() {
stubManager = mock(StubManager.class);
advice = mock(Advice.class);
}
@Test
public void shouldNotAttemptStubUnregister() {
StubLifecycleObserver slo = new StubLifecycleObserver(stubManager); | Interceptor interceptor = mock(Interceptor.class); |
wmaop/wm-aop | src/test/java/org/wmaop/aop/stub/StubLifecycleObserverTest.java | // Path: src/main/java/org/wmaop/aop/advice/Advice.java
// public class Advice {
//
// private final PointCut pointCut;
// private final Interceptor interceptor;
// private final String id;
// private AdviceState adviceState = AdviceState.NEW;
// private final Remit remit;
//
// public Advice(String id, Remit remit, PointCut pointCut, Interceptor interceptor) {
// this.pointCut = pointCut;
// this.interceptor = interceptor;
// this.id = id;
// this.remit = remit;
// }
//
// public Remit getRemit() {
// return remit;
// }
//
// public PointCut getPointCut() {
// return pointCut;
// }
//
// public boolean isApplicable(FlowPosition pipelinePosition, IData idata){
// return pointCut.isApplicable(pipelinePosition, idata) && remit.isApplicable();
// }
//
// public Interceptor getInterceptor() {
// return interceptor;
// }
//
// public String getId() {
// return id;
// }
//
// public AdviceState getAdviceState() {
// return adviceState;
// }
//
// public void setAdviceState(AdviceState adviceState) {
// this.adviceState = adviceState;
// }
//
// @Override
// public String toString() {
// return id + ' ' + adviceState + ' ' + pointCut + ' ' + interceptor + ' ' + pointCut.getInterceptPoint() + ' ' + remit;
// }
//
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("state", adviceState.toString());
// am.put("adviceId", id);
// am.put("pointcut", pointCut.toMap());
// am.put("interceptor", interceptor.toMap());
// am.put("remit", remit.toString());
// return am;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Advice other = (Advice) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/advice/AdviceState.java
// public enum AdviceState {
//
// NEW, ENABLED, DISABLED, DISPOSED;
// }
//
// Path: src/main/java/org/wmaop/aop/assertion/AssertionInterceptor.java
// public class AssertionInterceptor implements Interceptor, Assertable {
//
// private final String assertionName;
// private int invokeCount = 0;
// private boolean asserted;
//
// public AssertionInterceptor(String assertionName) {
// this.assertionName = assertionName;
// }
//
// public boolean performAssert(IData idata) {
// return true;
// }
//
// public void reset() {
// invokeCount = 0;
// asserted = false;
// }
//
// @Override
// public final InterceptResult intercept(FlowPosition flowPosition, IData idata) {
// invokeCount++;
// if (performAssert(idata)) {
// asserted = true;
// }
// return InterceptResult.FALSE;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// public boolean hasAsserted() {
// return asserted;
// }
//
// @Override
// public String getName() {
// return assertionName;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("assertionName", assertionName);
// am.put("invokeCount", invokeCount);
// am.put("asserted", Boolean.toString(asserted));
// return am;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/Interceptor.java
// public interface Interceptor {
//
// InterceptResult intercept(FlowPosition flowPosition, IData idata);
//
// int getInvokeCount();
//
// String getName();
//
// Map<String, Object> toMap();
//
// }
| import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.wmaop.aop.advice.Advice;
import org.wmaop.aop.advice.AdviceState;
import org.wmaop.aop.assertion.AssertionInterceptor;
import org.wmaop.aop.interceptor.Interceptor; | package org.wmaop.aop.stub;
public class StubLifecycleObserverTest {
private StubManager stubManager;
private Advice advice;
@Before
public void setup() {
stubManager = mock(StubManager.class);
advice = mock(Advice.class);
}
@Test
public void shouldNotAttemptStubUnregister() {
StubLifecycleObserver slo = new StubLifecycleObserver(stubManager);
Interceptor interceptor = mock(Interceptor.class);
when(advice.getInterceptor()).thenReturn(interceptor);
when(stubManager.hasStub((Advice) any())).thenReturn(false); | // Path: src/main/java/org/wmaop/aop/advice/Advice.java
// public class Advice {
//
// private final PointCut pointCut;
// private final Interceptor interceptor;
// private final String id;
// private AdviceState adviceState = AdviceState.NEW;
// private final Remit remit;
//
// public Advice(String id, Remit remit, PointCut pointCut, Interceptor interceptor) {
// this.pointCut = pointCut;
// this.interceptor = interceptor;
// this.id = id;
// this.remit = remit;
// }
//
// public Remit getRemit() {
// return remit;
// }
//
// public PointCut getPointCut() {
// return pointCut;
// }
//
// public boolean isApplicable(FlowPosition pipelinePosition, IData idata){
// return pointCut.isApplicable(pipelinePosition, idata) && remit.isApplicable();
// }
//
// public Interceptor getInterceptor() {
// return interceptor;
// }
//
// public String getId() {
// return id;
// }
//
// public AdviceState getAdviceState() {
// return adviceState;
// }
//
// public void setAdviceState(AdviceState adviceState) {
// this.adviceState = adviceState;
// }
//
// @Override
// public String toString() {
// return id + ' ' + adviceState + ' ' + pointCut + ' ' + interceptor + ' ' + pointCut.getInterceptPoint() + ' ' + remit;
// }
//
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("state", adviceState.toString());
// am.put("adviceId", id);
// am.put("pointcut", pointCut.toMap());
// am.put("interceptor", interceptor.toMap());
// am.put("remit", remit.toString());
// return am;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Advice other = (Advice) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/advice/AdviceState.java
// public enum AdviceState {
//
// NEW, ENABLED, DISABLED, DISPOSED;
// }
//
// Path: src/main/java/org/wmaop/aop/assertion/AssertionInterceptor.java
// public class AssertionInterceptor implements Interceptor, Assertable {
//
// private final String assertionName;
// private int invokeCount = 0;
// private boolean asserted;
//
// public AssertionInterceptor(String assertionName) {
// this.assertionName = assertionName;
// }
//
// public boolean performAssert(IData idata) {
// return true;
// }
//
// public void reset() {
// invokeCount = 0;
// asserted = false;
// }
//
// @Override
// public final InterceptResult intercept(FlowPosition flowPosition, IData idata) {
// invokeCount++;
// if (performAssert(idata)) {
// asserted = true;
// }
// return InterceptResult.FALSE;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// public boolean hasAsserted() {
// return asserted;
// }
//
// @Override
// public String getName() {
// return assertionName;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put("assertionName", assertionName);
// am.put("invokeCount", invokeCount);
// am.put("asserted", Boolean.toString(asserted));
// return am;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/Interceptor.java
// public interface Interceptor {
//
// InterceptResult intercept(FlowPosition flowPosition, IData idata);
//
// int getInvokeCount();
//
// String getName();
//
// Map<String, Object> toMap();
//
// }
// Path: src/test/java/org/wmaop/aop/stub/StubLifecycleObserverTest.java
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.wmaop.aop.advice.Advice;
import org.wmaop.aop.advice.AdviceState;
import org.wmaop.aop.assertion.AssertionInterceptor;
import org.wmaop.aop.interceptor.Interceptor;
package org.wmaop.aop.stub;
public class StubLifecycleObserverTest {
private StubManager stubManager;
private Advice advice;
@Before
public void setup() {
stubManager = mock(StubManager.class);
advice = mock(Advice.class);
}
@Test
public void shouldNotAttemptStubUnregister() {
StubLifecycleObserver slo = new StubLifecycleObserver(stubManager);
Interceptor interceptor = mock(Interceptor.class);
when(advice.getInterceptor()).thenReturn(interceptor);
when(stubManager.hasStub((Advice) any())).thenReturn(false); | when(advice.getAdviceState()).thenReturn(AdviceState.DISPOSED); |
wmaop/wm-aop | src/test/java/org/wmaop/aop/advice/remit/SessionRemitTest.java | // Path: src/main/java/org/wmaop/aop/advice/Scope.java
// public enum Scope {
// ALL, GLOBAL, SESSION, USER;
// }
| import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.wmaop.aop.advice.Scope; | package org.wmaop.aop.advice.remit;
public class SessionRemitTest {
@Test
public void shouldVerifyForKnownSessionID() {
SessionRemit sr = new SessionRemit("foo");
assertFalse(sr.isApplicable(null)); | // Path: src/main/java/org/wmaop/aop/advice/Scope.java
// public enum Scope {
// ALL, GLOBAL, SESSION, USER;
// }
// Path: src/test/java/org/wmaop/aop/advice/remit/SessionRemitTest.java
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.wmaop.aop.advice.Scope;
package org.wmaop.aop.advice.remit;
public class SessionRemitTest {
@Test
public void shouldVerifyForKnownSessionID() {
SessionRemit sr = new SessionRemit("foo");
assertFalse(sr.isApplicable(null)); | assertFalse(sr.isApplicable(Scope.ALL)); |
wmaop/wm-aop | src/test/java/org/wmaop/aop/matcher/FlowPositionMatcherTest.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
| package org.wmaop.aop.matcher;
public class FlowPositionMatcherTest {
@Test
public void shouldMatch() {
| // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
// Path: src/test/java/org/wmaop/aop/matcher/FlowPositionMatcherTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
package org.wmaop.aop.matcher;
public class FlowPositionMatcherTest {
@Test
public void shouldMatch() {
| assertTrue(new FlowPositionMatcherImpl("id", "foo:bar").match(new FlowPosition(InterceptPoint.INVOKE, "foo:bar")).isMatch());
|
wmaop/wm-aop | src/test/java/org/wmaop/aop/matcher/FlowPositionMatcherTest.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
| package org.wmaop.aop.matcher;
public class FlowPositionMatcherTest {
@Test
public void shouldMatch() {
| // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
// Path: src/test/java/org/wmaop/aop/matcher/FlowPositionMatcherTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
package org.wmaop.aop.matcher;
public class FlowPositionMatcherTest {
@Test
public void shouldMatch() {
| assertTrue(new FlowPositionMatcherImpl("id", "foo:bar").match(new FlowPosition(InterceptPoint.INVOKE, "foo:bar")).isMatch());
|
wmaop/wm-aop | src/test/java/org/wmaop/pipeline/FlowPositionTest.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
| import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint; | package org.wmaop.pipeline;
public class FlowPositionTest {
@Test
public void shouldParseServiceName() { | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
// Path: src/test/java/org/wmaop/pipeline/FlowPositionTest.java
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
package org.wmaop.pipeline;
public class FlowPositionTest {
@Test
public void shouldParseServiceName() { | FlowPosition fp1 = new FlowPosition(InterceptPoint.BEFORE, "foo"); |
wmaop/wm-aop | src/test/java/org/wmaop/pipeline/FlowPositionTest.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
| import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint; | package org.wmaop.pipeline;
public class FlowPositionTest {
@Test
public void shouldParseServiceName() { | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// BEFORE,INVOKE,AFTER;
//
// }
// Path: src/test/java/org/wmaop/pipeline/FlowPositionTest.java
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptPoint;
package org.wmaop.pipeline;
public class FlowPositionTest {
@Test
public void shouldParseServiceName() { | FlowPosition fp1 = new FlowPosition(InterceptPoint.BEFORE, "foo"); |
wmaop/wm-aop | src/main/java/org/wmaop/interceptor/pipline/PipelineCaptureInterceptor.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptionException.java
// public class InterceptionException extends RuntimeException {
//
// public InterceptionException(String message) {
// super(message);
// }
//
// public InterceptionException(Throwable cause) {
// super(cause);
// }
//
// public InterceptionException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/org/wmaop/interceptor/BaseInterceptor.java
// public abstract class BaseInterceptor implements Interceptor {
//
// public static final String MAP_INVOKE_COUNT = "invokeCount";
// public static final String MAP_NAME = "name";
// public static final String MAP_TYPE = "type";
//
// protected final String name;
// protected int invokeCount = 0;
//
// protected BaseInterceptor(String name) {
// this.name = name;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put(MAP_NAME, name);
// am.put(MAP_INVOKE_COUNT, invokeCount);
// addMap(am);
// return am;
// }
//
// protected abstract void addMap(Map<String, Object> am);
//
// }
| import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.aop.interceptor.InterceptionException;
import org.wmaop.interceptor.BaseInterceptor;
import com.wm.data.IData;
import com.wm.util.coder.IDataXMLCoder; | package org.wmaop.interceptor.pipline;
public class PipelineCaptureInterceptor extends BaseInterceptor {
public static final String MAP_CURRENT_FILE = "currentFile";
private final String prefix;
private final String suffix;
private int fileCount;
public PipelineCaptureInterceptor(String fileName) {
super("PipelineCapture-"+fileName);
int dotPos = fileName.lastIndexOf('.');
if (dotPos == -1) {
prefix = fileName;
suffix = ".xml";
} else {
prefix = fileName.substring(0, dotPos);
suffix = fileName.substring(dotPos);
}
}
@Override | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptionException.java
// public class InterceptionException extends RuntimeException {
//
// public InterceptionException(String message) {
// super(message);
// }
//
// public InterceptionException(Throwable cause) {
// super(cause);
// }
//
// public InterceptionException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/org/wmaop/interceptor/BaseInterceptor.java
// public abstract class BaseInterceptor implements Interceptor {
//
// public static final String MAP_INVOKE_COUNT = "invokeCount";
// public static final String MAP_NAME = "name";
// public static final String MAP_TYPE = "type";
//
// protected final String name;
// protected int invokeCount = 0;
//
// protected BaseInterceptor(String name) {
// this.name = name;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put(MAP_NAME, name);
// am.put(MAP_INVOKE_COUNT, invokeCount);
// addMap(am);
// return am;
// }
//
// protected abstract void addMap(Map<String, Object> am);
//
// }
// Path: src/main/java/org/wmaop/interceptor/pipline/PipelineCaptureInterceptor.java
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.aop.interceptor.InterceptionException;
import org.wmaop.interceptor.BaseInterceptor;
import com.wm.data.IData;
import com.wm.util.coder.IDataXMLCoder;
package org.wmaop.interceptor.pipline;
public class PipelineCaptureInterceptor extends BaseInterceptor {
public static final String MAP_CURRENT_FILE = "currentFile";
private final String prefix;
private final String suffix;
private int fileCount;
public PipelineCaptureInterceptor(String fileName) {
super("PipelineCapture-"+fileName);
int dotPos = fileName.lastIndexOf('.');
if (dotPos == -1) {
prefix = fileName;
suffix = ".xml";
} else {
prefix = fileName.substring(0, dotPos);
suffix = fileName.substring(dotPos);
}
}
@Override | public InterceptResult intercept(FlowPosition flowPosition, IData idata) { |
wmaop/wm-aop | src/main/java/org/wmaop/interceptor/pipline/PipelineCaptureInterceptor.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptionException.java
// public class InterceptionException extends RuntimeException {
//
// public InterceptionException(String message) {
// super(message);
// }
//
// public InterceptionException(Throwable cause) {
// super(cause);
// }
//
// public InterceptionException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/org/wmaop/interceptor/BaseInterceptor.java
// public abstract class BaseInterceptor implements Interceptor {
//
// public static final String MAP_INVOKE_COUNT = "invokeCount";
// public static final String MAP_NAME = "name";
// public static final String MAP_TYPE = "type";
//
// protected final String name;
// protected int invokeCount = 0;
//
// protected BaseInterceptor(String name) {
// this.name = name;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put(MAP_NAME, name);
// am.put(MAP_INVOKE_COUNT, invokeCount);
// addMap(am);
// return am;
// }
//
// protected abstract void addMap(Map<String, Object> am);
//
// }
| import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.aop.interceptor.InterceptionException;
import org.wmaop.interceptor.BaseInterceptor;
import com.wm.data.IData;
import com.wm.util.coder.IDataXMLCoder; | package org.wmaop.interceptor.pipline;
public class PipelineCaptureInterceptor extends BaseInterceptor {
public static final String MAP_CURRENT_FILE = "currentFile";
private final String prefix;
private final String suffix;
private int fileCount;
public PipelineCaptureInterceptor(String fileName) {
super("PipelineCapture-"+fileName);
int dotPos = fileName.lastIndexOf('.');
if (dotPos == -1) {
prefix = fileName;
suffix = ".xml";
} else {
prefix = fileName.substring(0, dotPos);
suffix = fileName.substring(dotPos);
}
}
@Override | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptionException.java
// public class InterceptionException extends RuntimeException {
//
// public InterceptionException(String message) {
// super(message);
// }
//
// public InterceptionException(Throwable cause) {
// super(cause);
// }
//
// public InterceptionException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/org/wmaop/interceptor/BaseInterceptor.java
// public abstract class BaseInterceptor implements Interceptor {
//
// public static final String MAP_INVOKE_COUNT = "invokeCount";
// public static final String MAP_NAME = "name";
// public static final String MAP_TYPE = "type";
//
// protected final String name;
// protected int invokeCount = 0;
//
// protected BaseInterceptor(String name) {
// this.name = name;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put(MAP_NAME, name);
// am.put(MAP_INVOKE_COUNT, invokeCount);
// addMap(am);
// return am;
// }
//
// protected abstract void addMap(Map<String, Object> am);
//
// }
// Path: src/main/java/org/wmaop/interceptor/pipline/PipelineCaptureInterceptor.java
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.aop.interceptor.InterceptionException;
import org.wmaop.interceptor.BaseInterceptor;
import com.wm.data.IData;
import com.wm.util.coder.IDataXMLCoder;
package org.wmaop.interceptor.pipline;
public class PipelineCaptureInterceptor extends BaseInterceptor {
public static final String MAP_CURRENT_FILE = "currentFile";
private final String prefix;
private final String suffix;
private int fileCount;
public PipelineCaptureInterceptor(String fileName) {
super("PipelineCapture-"+fileName);
int dotPos = fileName.lastIndexOf('.');
if (dotPos == -1) {
prefix = fileName;
suffix = ".xml";
} else {
prefix = fileName.substring(0, dotPos);
suffix = fileName.substring(dotPos);
}
}
@Override | public InterceptResult intercept(FlowPosition flowPosition, IData idata) { |
wmaop/wm-aop | src/main/java/org/wmaop/interceptor/pipline/PipelineCaptureInterceptor.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptionException.java
// public class InterceptionException extends RuntimeException {
//
// public InterceptionException(String message) {
// super(message);
// }
//
// public InterceptionException(Throwable cause) {
// super(cause);
// }
//
// public InterceptionException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/org/wmaop/interceptor/BaseInterceptor.java
// public abstract class BaseInterceptor implements Interceptor {
//
// public static final String MAP_INVOKE_COUNT = "invokeCount";
// public static final String MAP_NAME = "name";
// public static final String MAP_TYPE = "type";
//
// protected final String name;
// protected int invokeCount = 0;
//
// protected BaseInterceptor(String name) {
// this.name = name;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put(MAP_NAME, name);
// am.put(MAP_INVOKE_COUNT, invokeCount);
// addMap(am);
// return am;
// }
//
// protected abstract void addMap(Map<String, Object> am);
//
// }
| import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.aop.interceptor.InterceptionException;
import org.wmaop.interceptor.BaseInterceptor;
import com.wm.data.IData;
import com.wm.util.coder.IDataXMLCoder; | package org.wmaop.interceptor.pipline;
public class PipelineCaptureInterceptor extends BaseInterceptor {
public static final String MAP_CURRENT_FILE = "currentFile";
private final String prefix;
private final String suffix;
private int fileCount;
public PipelineCaptureInterceptor(String fileName) {
super("PipelineCapture-"+fileName);
int dotPos = fileName.lastIndexOf('.');
if (dotPos == -1) {
prefix = fileName;
suffix = ".xml";
} else {
prefix = fileName.substring(0, dotPos);
suffix = fileName.substring(dotPos);
}
}
@Override
public InterceptResult intercept(FlowPosition flowPosition, IData idata) {
invokeCount++;
++fileCount;
try (OutputStream fos = getFileOutputStream(getFileName())) {
new IDataXMLCoder().encode(fos, idata);
} catch (IOException e) { | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptionException.java
// public class InterceptionException extends RuntimeException {
//
// public InterceptionException(String message) {
// super(message);
// }
//
// public InterceptionException(Throwable cause) {
// super(cause);
// }
//
// public InterceptionException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// Path: src/main/java/org/wmaop/interceptor/BaseInterceptor.java
// public abstract class BaseInterceptor implements Interceptor {
//
// public static final String MAP_INVOKE_COUNT = "invokeCount";
// public static final String MAP_NAME = "name";
// public static final String MAP_TYPE = "type";
//
// protected final String name;
// protected int invokeCount = 0;
//
// protected BaseInterceptor(String name) {
// this.name = name;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put(MAP_NAME, name);
// am.put(MAP_INVOKE_COUNT, invokeCount);
// addMap(am);
// return am;
// }
//
// protected abstract void addMap(Map<String, Object> am);
//
// }
// Path: src/main/java/org/wmaop/interceptor/pipline/PipelineCaptureInterceptor.java
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.aop.interceptor.InterceptionException;
import org.wmaop.interceptor.BaseInterceptor;
import com.wm.data.IData;
import com.wm.util.coder.IDataXMLCoder;
package org.wmaop.interceptor.pipline;
public class PipelineCaptureInterceptor extends BaseInterceptor {
public static final String MAP_CURRENT_FILE = "currentFile";
private final String prefix;
private final String suffix;
private int fileCount;
public PipelineCaptureInterceptor(String fileName) {
super("PipelineCapture-"+fileName);
int dotPos = fileName.lastIndexOf('.');
if (dotPos == -1) {
prefix = fileName;
suffix = ".xml";
} else {
prefix = fileName.substring(0, dotPos);
suffix = fileName.substring(dotPos);
}
}
@Override
public InterceptResult intercept(FlowPosition flowPosition, IData idata) {
invokeCount++;
++fileCount;
try (OutputStream fos = getFileOutputStream(getFileName())) {
new IDataXMLCoder().encode(fos, idata);
} catch (IOException e) { | throw new InterceptionException("Error when writing pipeline to file " + getFileName(),e); |
wmaop/wm-aop | src/main/java/org/wmaop/interceptor/mock/exception/ExceptionInterceptor.java | // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/interceptor/BaseInterceptor.java
// public abstract class BaseInterceptor implements Interceptor {
//
// public static final String MAP_INVOKE_COUNT = "invokeCount";
// public static final String MAP_NAME = "name";
// public static final String MAP_TYPE = "type";
//
// protected final String name;
// protected int invokeCount = 0;
//
// protected BaseInterceptor(String name) {
// this.name = name;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put(MAP_NAME, name);
// am.put(MAP_INVOKE_COUNT, invokeCount);
// addMap(am);
// return am;
// }
//
// protected abstract void addMap(Map<String, Object> am);
//
// }
| import java.lang.reflect.Constructor;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.interceptor.BaseInterceptor;
import com.wm.data.IData; | package org.wmaop.interceptor.mock.exception;
public class ExceptionInterceptor extends BaseInterceptor {
public static final String MAP_EXCEPTION = "exception";
| // Path: src/main/java/org/wmaop/aop/interceptor/FlowPosition.java
// public class FlowPosition {
//
// public final String packageName;
// public final String serviceName;
// public final String fqname;
// private InterceptPoint interceptPoint;
//
// public FlowPosition(InterceptPoint point, String fqname) {
// interceptPoint = point;
// if (fqname == null) {
// serviceName = "";
// packageName = "";
// this.fqname = "";
// } else {
// this.fqname = fqname;
// int pkgsep = fqname.lastIndexOf(':');
// if (pkgsep == -1) {
// serviceName = fqname;
// packageName = "";
// } else {
// serviceName = fqname.substring(pkgsep + 1);
// packageName = fqname.substring(0, pkgsep);
// }
// }
// }
//
// @Override
// public String toString() {
// return fqname;
// }
//
// public void setInterceptPoint(InterceptPoint point) {
// interceptPoint = point;
// }
//
// public InterceptPoint getInterceptPoint() {
// return interceptPoint;
// }
//
// public String getPackageName() {
// return packageName;
// }
//
// public String getServiceName() {
// return serviceName;
// }
//
// public String getFqname() {
// return fqname;
// }
// }
//
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptResult.java
// public class InterceptResult {
//
// public static final InterceptResult TRUE = new InterceptResult(true);
// public static final InterceptResult FALSE = new InterceptResult(false);
//
// private final boolean hasIntercepted;
// private final Exception exception;
//
// public InterceptResult(boolean hasIntercepted) {
// this.hasIntercepted = hasIntercepted;
// exception = null;
// }
//
// public InterceptResult(boolean hasIntercepted, Exception e) {
// this.exception = e;
// this.hasIntercepted = hasIntercepted;
// }
//
// public boolean hasIntercepted() {
// return hasIntercepted;
// }
//
// public Exception getException() {
// return exception;
// }
//
//
// }
//
// Path: src/main/java/org/wmaop/interceptor/BaseInterceptor.java
// public abstract class BaseInterceptor implements Interceptor {
//
// public static final String MAP_INVOKE_COUNT = "invokeCount";
// public static final String MAP_NAME = "name";
// public static final String MAP_TYPE = "type";
//
// protected final String name;
// protected int invokeCount = 0;
//
// protected BaseInterceptor(String name) {
// this.name = name;
// }
//
// @Override
// public int getInvokeCount() {
// return invokeCount;
// }
//
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public Map<String, Object> toMap() {
// Map<String, Object> am = new HashMap<>();
// am.put(MAP_NAME, name);
// am.put(MAP_INVOKE_COUNT, invokeCount);
// addMap(am);
// return am;
// }
//
// protected abstract void addMap(Map<String, Object> am);
//
// }
// Path: src/main/java/org/wmaop/interceptor/mock/exception/ExceptionInterceptor.java
import java.lang.reflect.Constructor;
import java.util.Map;
import org.wmaop.aop.interceptor.FlowPosition;
import org.wmaop.aop.interceptor.InterceptResult;
import org.wmaop.interceptor.BaseInterceptor;
import com.wm.data.IData;
package org.wmaop.interceptor.mock.exception;
public class ExceptionInterceptor extends BaseInterceptor {
public static final String MAP_EXCEPTION = "exception";
| private final InterceptResult interceptResult; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.