Skip to content

Commit

Permalink
GEODE-1276: Change UnitTests file system to IntegrationTest category
Browse files Browse the repository at this point in the history
GEODE-1307: Rename HeterogenousLuceneSerializer to HeterogeneousLuceneSerializer
GEODE-1279: Tests for old TRAC bugs should be renamed to useful name

* convert UnitTests to use JUnit 4 syntax
* convert UnitTests to use Rules
* remove empty javadoc blocks and lines
* separate some UnitTests from IntegrationTests (ie split one test into two tests)
* fix up formatting problems
* improve testability of ClassPathLoader
* rename some tests from old TRAC #s to meaningful names
* remove empty unnecessary methods and deadcode
* add @OverRide annotations
* reduce scope of variables and methods where possible
  • Loading branch information
kirklund committed May 6, 2016
1 parent 4ad4d63 commit bf258f6
Show file tree
Hide file tree
Showing 374 changed files with 6,513 additions and 6,648 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public void call(HttpServletRequest request, HttpServletResponse response)
// request.setURI("/test/request2");
// response.parse(tester.getResponses(request.generate()));
//
// assertEquals("null", response.getContent());
// assertIndexDetailsEquals("null", response.getContent());
//
// Region r = getRegion();
// assertNull("Region should not contain session", r.get(id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import org.junit.BeforeClass;
import org.junit.experimental.categories.Category;

/**
*/
@Category(UnitTest.class)
public class Tomcat7SessionsJUnitTest extends TestSessionsBase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@

import static junit.framework.Assert.*;

/**
*
*/
public abstract class TestSessionsBase {

private static EmbeddedTomcat server;

private static Region<String, HttpSession> region;
Expand All @@ -68,7 +66,7 @@ public static void setupServer(DeltaSessionManager manager) throws Exception {
servlet = server.addServlet("/test/*", "default", CommandServlet.class.getName());
server.startContainer();

/**
/*
* Can only retrieve the region once the container has started up
* (and the cache has started too).
*/
Expand Down Expand Up @@ -212,7 +210,7 @@ public void testSessionPersists1() throws Exception {
// req.removeParameter("value");
// response = wc.getResponse(req);
//
// assertEquals(value, response.getText());
// assertIndexDetailsEquals(value, response.getText());
// }

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import org.junit.BeforeClass;
import org.junit.experimental.categories.Category;

/**
*/
@Category(UnitTest.class)
public class Tomcat6SessionsJUnitTest extends TestSessionsBase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
import org.junit.experimental.categories.Category;

import com.gemstone.gemfire.internal.FileUtil;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
import com.gemstone.gemfire.util.test.TestUtil;

@Category(UnitTest.class)
@Category(IntegrationTest.class)
public class BundledJarsJUnitTest {

private static final String VERSION_PATTERN = "[0-9-_.v]{3,}.*\\.jar$";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ public void test011StopLocatorUsingMemberName() {

// TODO figure out what output to assert and validate on now that 'stop locator' uses Gfsh's logger
// and standard err/out...
//assertEquals(CliStrings.format(CliStrings.STOP_LOCATOR__SHUTDOWN_MEMBER_MESSAGE, pathname),
//assertIndexDetailsEquals(CliStrings.format(CliStrings.STOP_LOCATOR__SHUTDOWN_MEMBER_MESSAGE, pathname),
// StringUtils.trim(toString(result)));

WaitCriterion waitCriteria = new WaitCriterion() {
Expand Down Expand Up @@ -792,7 +792,7 @@ public void test012StopLocatorUsingMemberId() throws Exception {

// TODO figure out what output to assert and validate on now that 'stop locator' uses Gfsh's logger
// and standard err/out...
//assertEquals(CliStrings.format(CliStrings.STOP_LOCATOR__SHUTDOWN_MEMBER_MESSAGE, memberId),
//assertIndexDetailsEquals(CliStrings.format(CliStrings.STOP_LOCATOR__SHUTDOWN_MEMBER_MESSAGE, memberId),
// StringUtils.trim(toString(result)));

WaitCriterion waitCriteria = new WaitCriterion() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gemstone.gemfire.management.internal.cli.commands;

import static org.junit.Assert.*;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.jar.Attributes;
import java.util.jar.Attributes.Name;
import java.util.jar.JarFile;
import java.util.jar.Manifest;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestName;

import com.gemstone.gemfire.internal.util.IOUtils;
import com.gemstone.gemfire.test.junit.categories.IntegrationTest;

/**
* The LauncherLifecycleCommandsJUnitTest class is a test suite of test cases testing the contract and functionality of
* the lifecycle launcher GemFire shell (Gfsh) commands.
*
* @see com.gemstone.gemfire.management.internal.cli.commands.LauncherLifecycleCommands
* @see org.junit.Assert
* @see org.junit.Test
* @since 7.0
*/
@Category(IntegrationTest.class)
public class LauncherLifecycleCommandsIntegrationTest {

private LauncherLifecycleCommands launcherCommands;

@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();

@Rule
public TestName testName = new TestName();

@Before
public void setup() {
launcherCommands = new LauncherLifecycleCommands();
}

@After
public void tearDown() {
launcherCommands = null;
}

@Test
public void testGemFireCoreClasspath() throws IOException {
File coreDependenciesJar = new File(LauncherLifecycleCommands.CORE_DEPENDENCIES_JAR_PATHNAME);

assertNotNull(coreDependenciesJar);
assertTrue(coreDependenciesJar + " is not a file", coreDependenciesJar.isFile());

Collection<String> expectedJarDependencies = Arrays.asList("antlr", "commons-io", "commons-lang", "commons-logging",
"geode", "jackson-annotations", "jackson-core", "jackson-databind", "jansi", "jline", "snappy-java",
"spring-core", "spring-shell", "jetty-server", "jetty-servlet", "jetty-webapp", "jetty-util", "jetty-http",
"servlet-api", "jetty-io", "jetty-security", "jetty-xml"

);

assertJarFileManifestClassPath(coreDependenciesJar, expectedJarDependencies);
}

@Test
public void testReadPid() throws IOException {
final int expectedPid = 12345;

File folder = temporaryFolder.newFolder();
File pidFile = new File(folder, getClass().getSimpleName() + "_" + testName.getMethodName() + ".pid");

assertTrue(pidFile.createNewFile());

pidFile.deleteOnExit();
writePid(pidFile, expectedPid);

final int actualPid = getLauncherLifecycleCommands().readPid(pidFile);

assertEquals(expectedPid, actualPid);
}

private LauncherLifecycleCommands getLauncherLifecycleCommands() {
return launcherCommands;
}

private void writePid(final File pidFile, final int pid) throws IOException {
final FileWriter fileWriter = new FileWriter(pidFile, false);
fileWriter.write(String.valueOf(pid));
fileWriter.write("\n");
fileWriter.flush();
IOUtils.close(fileWriter);
}

private void assertJarFileManifestClassPath(final File dependenciesJar,
final Collection<String> expectedJarDependencies) throws IOException {
JarFile dependenciesJarFile = new JarFile(dependenciesJar);
Manifest manifest = dependenciesJarFile.getManifest();

assertNotNull(manifest);

Attributes attributes = manifest.getMainAttributes();

assertNotNull(attributes);
assertTrue(attributes.containsKey(Name.CLASS_PATH));

String[] actualJarDependencies = attributes.getValue(Name.CLASS_PATH).split(" ");

assertNotNull(actualJarDependencies);
assertTrue(String.format("Expected the actual number of JAR dependencies to be (%1$d); but was (%2$d)!",
expectedJarDependencies.size(), actualJarDependencies.length),
actualJarDependencies.length >= expectedJarDependencies.size());
//assertTrue(Arrays.asList(actualJarDependencies).containsAll(expectedJarDependencies));

List<String> actualJarDependenciesList = new ArrayList<>(Arrays.asList(actualJarDependencies));
List<String> missingExpectedJarDependenciesList = new ArrayList<>(expectedJarDependencies.size());

for (String expectedJarDependency : expectedJarDependencies) {
boolean containsExpectedJar = false;

for (int index = 0, size = actualJarDependenciesList.size(); index < size; index++) {
if (actualJarDependenciesList.get(index).toLowerCase().contains(expectedJarDependency.toLowerCase())) {
actualJarDependenciesList.remove(index);
containsExpectedJar = true;
break;
}
}

if (!containsExpectedJar) {
missingExpectedJarDependenciesList.add(expectedJarDependency);
}
}

assertTrue(String.format(
"GemFire dependencies JAR file (%1$s) does not contain the expected dependencies (%2$s) in the Manifest Class-Path attribute (%3$s)!",
dependenciesJar, missingExpectedJarDependenciesList, attributes.getValue(Name.CLASS_PATH)),
missingExpectedJarDependenciesList.isEmpty());
}

}
Loading

0 comments on commit bf258f6

Please sign in to comment.