Skip to content

Commit

Permalink
Merge pull request #239 from jeffmaury/OSJC-274
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot committed Nov 9, 2016
2 parents 76a5ca4 + 084d339 commit 461469e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<!-- Artifact Information -->
<groupId>com.openshift</groupId>
<artifactId>openshift-restclient-java</artifactId>
<version>5.2.0.Final</version>
<version>5.3.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>OpenShift Java REST Client</name>
<url>http://openshift.redhat.com</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,33 @@ public IObjectReference getBuildOutputReference() {
@Override
public List<IBuildTrigger> getBuildTriggers() {
List<IBuildTrigger> triggers = new ArrayList<IBuildTrigger>();
List<ModelNode> list = get(BUILDCONFIG_TRIGGERS).asList();
final String url = getClient() != null ? getClient().getResourceURI(this) : "";
for (ModelNode node : list) {
String type = node.get(TYPE).asString();
switch(type){
case BuildTriggerType.GENERIC:
triggers.add(new WebhookTrigger(BuildTriggerType.GENERIC,
asString(node, BUILD_CONFIG_WEBHOOK_GENERIC_SECRET), url));
break;
case BuildTriggerType.GITHUB:
triggers.add(new WebhookTrigger(BuildTriggerType.GITHUB, asString(node, BUILD_CONFIG_WEBHOOK_GITHUB_SECRET), url));
break;
case BuildTriggerType.IMAGE_CHANGE:
triggers.add(new ImageChangeTrigger(BuildTriggerType.IMAGE_CHANGE,
asString(node, BUILD_CONFIG_IMAGECHANGE_IMAGE),
asString(node, BUILD_CONFIG_IMAGECHANGE_NAME),
asString(node, BUILD_CONFIG_IMAGECHANGE_TAG))
);
break;
case BuildTriggerType.CONFIG_CHANGE:
triggers.add(new ImageChangeTrigger(BuildTriggerType.CONFIG_CHANGE, null, null));
default:
}
}
return triggers;
if (has(BUILDCONFIG_TRIGGERS)) {
List<ModelNode> list = get(BUILDCONFIG_TRIGGERS).asList();
final String url = getClient() != null && StringUtils.isNotEmpty(getNamespace()) ? getClient().getResourceURI(this) : "";
for (ModelNode node : list) {
String type = node.get(TYPE).asString();
switch (type) {
case BuildTriggerType.GENERIC:
triggers.add(new WebhookTrigger(BuildTriggerType.GENERIC,
asString(node, BUILD_CONFIG_WEBHOOK_GENERIC_SECRET), url));
break;
case BuildTriggerType.GITHUB:
triggers.add(new WebhookTrigger(BuildTriggerType.GITHUB,
asString(node, BUILD_CONFIG_WEBHOOK_GITHUB_SECRET), url));
break;
case BuildTriggerType.IMAGE_CHANGE:
triggers.add(new ImageChangeTrigger(BuildTriggerType.IMAGE_CHANGE,
asString(node, BUILD_CONFIG_IMAGECHANGE_IMAGE),
asString(node, BUILD_CONFIG_IMAGECHANGE_NAME),
asString(node, BUILD_CONFIG_IMAGECHANGE_TAG)));
break;
case BuildTriggerType.CONFIG_CHANGE:
triggers.add(new ImageChangeTrigger(BuildTriggerType.CONFIG_CHANGE, null, null));
default:
}
}
}
return triggers;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2016 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package com.openshift.internal.restclient.model;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;

import java.util.HashMap;

import org.jboss.dmr.ModelNode;
import org.junit.Before;
import org.junit.Test;

import com.openshift.restclient.IClient;
import com.openshift.restclient.model.IBuildConfig;

/**
* Tests unrelated to the underlying model structure and
* should api version independent
* @author Jeff Maury
*
*/
public class BuildConfigTest {

private IBuildConfig config;

@Before
public void setUp() throws Exception {
config = new BuildConfig(new ModelNode(), mock(IClient.class), new HashMap<>());
}

@Test
public void testBuildTriggersShouldReturn() {
assertEquals(0, config.getBuildTriggers().size());
}

}

0 comments on commit 461469e

Please sign in to comment.