Skip to content

Commit

Permalink
Updates for unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
PFHJYG0 committed Aug 8, 2017
1 parent 022f6fd commit 194e6b1
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 255 deletions.
123 changes: 38 additions & 85 deletions src/main/java/com/compuware/jenkins/scm/CpwrScmConfiguration.java
Expand Up @@ -3,19 +3,17 @@
*
* Copyright (c) 2017 Compuware Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions: The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.compuware.jenkins.scm;

import java.io.PrintStream;
Expand Down Expand Up @@ -70,33 +68,33 @@ protected CpwrScmConfiguration(String connectionId, String filterPattern, String
m_credentialsId = StringUtils.trimToEmpty(credentialsId);
}

/**
* Handle data migration
*
* In 2.0 "hostPort" and "codePage" were removed and replaced by a list of host connections. This list is
* a global and created with the Global Configuration page. If old hostPort and codePage properties exist, then
* a an attempt is made to create a new host connection with these properties and add it to the list of global
* host connections, as long as there is no other host connection already existing with the same properties.
*
* @return the configuration
*/
protected Object readResolve()
{
// Migrate from 1.X to 2.0
if (m_hostPort != null && m_codePage != null)
{
CpwrGlobalConfiguration globalConfig = CpwrGlobalConfiguration.get();
if (!globalConfig.hostConnectionExists(m_hostPort, m_codePage))
{
String description = m_hostPort + " " + m_codePage; //$NON-NLS-1$
HostConnection connection = new HostConnection(description, m_hostPort, m_codePage, null, null);
globalConfig.addHostConnection(connection);
m_connectionId = connection.getConnectionId();
}
}
/**
* Handle data migration
*
* In 2.0 "hostPort" and "codePage" were removed and replaced by a list of host connections. This list is a global and
* created with the Global Configuration page. If old hostPort and codePage properties exist, then a an attempt is made to
* create a new host connection with these properties and add it to the list of global host connections, as long as there is
* no other host connection already existing with the same properties.
*
* @return the configuration
*/
protected Object readResolve()
{
// Migrate from 1.X to 2.0
if (m_hostPort != null && m_codePage != null)
{
CpwrGlobalConfiguration globalConfig = CpwrGlobalConfiguration.get();
if (!globalConfig.hostConnectionExists(m_hostPort, m_codePage))
{
String description = m_hostPort + " " + m_codePage; //$NON-NLS-1$
HostConnection connection = new HostConnection(description, m_hostPort, m_codePage, null, null);
globalConfig.addHostConnection(connection);
m_connectionId = connection.getConnectionId();
}
}

return this;
}
return this;
}

/*
* (non-Javadoc)
Expand All @@ -108,16 +106,6 @@ public ChangeLogParser createChangeLogParser()
return null;
}

/**
* Gets the value of the 'Host:Port'.
*
* @return <code>String</code> value of m_hostport
*/
public String getHostPort()
{
return m_hostPort;
}

/**
* Gets the unique identifier of the 'Host connection'.
*
Expand All @@ -128,16 +116,6 @@ public String getConnectionId()
return m_connectionId;
}

/**
* Gets the value of the 'Code Page'.
*
* @return <code>String</code> value of m_codePage
*/
public String getCodePage()
{
return m_codePage;
}

/**
* Gets the value of the 'Filter pattern'.
*
Expand Down Expand Up @@ -168,30 +146,6 @@ public String getCredentialsId()
return m_credentialsId;
}

/**
* Retrieves host connection information given a host connection id.
*
* @return a Jenkins host connection
*/
protected HostConnection getHostConnection()
{
HostConnection connection = null;

CpwrGlobalConfiguration globalConfig = CpwrGlobalConfiguration.get();
HostConnection[] hostConnections = globalConfig.getHostConnections();

String connectionId = getConnectionId();
for (HostConnection c : hostConnections)
{
if (connectionId.matches(c.getConnectionId()))
{
connection = c;
}
}

return connection;
}

/**
* Retrieves login information given a credential ID.
*
Expand All @@ -204,9 +158,8 @@ protected StandardUsernamePasswordCredentials getLoginInformation(Item project)
{
StandardUsernamePasswordCredentials credential = null;

List<StandardUsernamePasswordCredentials> credentials = CredentialsProvider
.lookupCredentials(StandardUsernamePasswordCredentials.class, project, ACL.SYSTEM,
Collections.<DomainRequirement> emptyList());
List<StandardUsernamePasswordCredentials> credentials = CredentialsProvider.lookupCredentials(
StandardUsernamePasswordCredentials.class, project, ACL.SYSTEM, Collections.<DomainRequirement> emptyList());

IdMatcher matcher = new IdMatcher(getCredentialsId());
for (StandardUsernamePasswordCredentials c : credentials)
Expand Down
50 changes: 41 additions & 9 deletions src/main/java/com/compuware/jenkins/scm/IspwConfiguration.java
Expand Up @@ -58,15 +58,19 @@
*/
public class IspwConfiguration extends SCM
{
private final String m_connectionId;
private final String m_credentialsId;
private final String m_serverConfig;
private final String m_serverStream;
private final String m_serverApplication;
private final String m_serverLevel;
private final String m_levelOption;
private final String m_filterType;
private final String m_filterName;
private String m_connectionId;
private String m_credentialsId;
private String m_serverConfig;
private String m_serverStream;
private String m_serverApplication;
private String m_serverLevel;
private String m_levelOption;
private String m_filterType;
private String m_filterName;

// Backward compatibility
private transient @Deprecated String m_hostPort;
private transient @Deprecated String m_codePage;

@DataBoundConstructor
public IspwConfiguration(String connectionId, String credentialsId, String serverConfig, String serverStream,
Expand Down Expand Up @@ -126,6 +130,34 @@ public void checkout(Run<?, ?> build, Launcher launcher, FilePath workspaceFileP
}
}

/**
* Handle data migration
*
* In 2.0 "hostPort" and "codePage" were removed and replaced by a list of host connections. This list is
* a global and created with the Global Configuration page. If old hostPort and codePage properties exist, then
* a an attempt is made to create a new host connection with these properties and add it to the list of global
* host connections, as long as there is no other host connection already existing with the same properties.
*
* @return the configuration
*/
protected Object readResolve()
{
// Migrate from 1.X to 2.0
if (m_hostPort != null && m_codePage != null)
{
CpwrGlobalConfiguration globalConfig = CpwrGlobalConfiguration.get();
if (!globalConfig.hostConnectionExists(m_hostPort, m_codePage))
{
String description = m_hostPort + " " + m_codePage; //$NON-NLS-1$
HostConnection connection = new HostConnection(description, m_hostPort, m_codePage, null, null);
globalConfig.addHostConnection(connection);
m_connectionId = connection.getConnectionId();
}
}

return this;
}

/* (non-Javadoc)
* @see hudson.scm.SCM#createChangeLogParser()
*/
Expand Down

This file was deleted.

This file was deleted.

Expand Up @@ -17,40 +17,21 @@
package com.compuware.jenkins.scm;

import static org.junit.Assert.fail;
import java.io.IOException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.LocalData;
import com.compuware.jenkins.scm.util.CpwrScmConfigTestUtils;
import com.compuware.jenkins.scm.util.ScmTestUtils;

/**
* PdsConfiguration unit tests.
* Endevor data migration unit test.
*/
@SuppressWarnings("nls")
public class EndevorMigrateDataTest
{
// Member Variables
@Rule
public JenkinsRule m_jenkinsRule = new JenkinsRule();

@Before
public void setup()
{
try
{
ScmTestUtils.setupGlobalConfiguration();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}

/**
* Perform a round trip test on the configuration.
* <p>
Expand Down

0 comments on commit 194e6b1

Please sign in to comment.