Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;

Expand Down Expand Up @@ -196,6 +197,7 @@ protected void set(String key, int value) {
}

protected void set(String key, String value){
value = StringUtils.defaultIfBlank(value, "");
node.get(getPath(key)).set(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,26 @@ public class OpenshiftProjectRequest extends KubernetesResource implements IProj

public OpenshiftProjectRequest(ModelNode node, IClient client, Map<String, String[]> propertyKeys) {
super(node, client, propertyKeys);
// TODO Auto-generated constructor stub
}

@Override
public void setDisplayName(String name) {
set(DISPLAYNAME, name);
}

@Override
public String getDisplayName() {
return asString(DISPLAYNAME);
}

@Override
public void setDescription(String description) {
set(DESCRIPTION, description);
}

@Override
public String getDescription() {
return asString(DESCRIPTION);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public interface OpenShiftApiModelProperties extends ResourcePropertyKeys{
put(ANNOTATIONS, new String [] {"metadata", "annotations"});
put(APIVERSION, new String [] {"apiVersion"});
put(CREATION_TIMESTAMP, new String [] {"metadata", "creationTimestamp"});
put(DESCRIPTION, new String [] { "description"});
put(DISPLAYNAME, new String [] { "displayName"});
put(LABELS, new String [] { "metadata","labels"});
put(LABELS, new String [] { "metadata","labels"});
put(NAME , new String [] {"metadata", "name"});
put(NAMESPACE, new String [] {"metadata", "namespace"});
Expand Down Expand Up @@ -159,6 +162,8 @@ public interface OpenShiftApiModelProperties extends ResourcePropertyKeys{
put(ANNOTATIONS, new String [] {"metadata", "annotations"});
put(APIVERSION, new String [] {"apiVersion"});
put(CREATION_TIMESTAMP, new String [] {"metadata", "creationTimestamp"});
put(DESCRIPTION, new String [] { "description"});
put(DISPLAYNAME, new String [] { "displayName"});
put(LABELS, new String [] { "metadata","labels"});
put(NAME , new String [] {"metadata", "name"});
put(NAMESPACE, new String [] {"metadata", "namespace"});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public interface ResourcePropertyKeys extends BuildConfigPropertyKeys{
static final String APIVERSION = "apiversion";
static final String CREATION_TIMESTAMP = "creationTimestamp";
static final String DISPLAYNAME = "displayName";
static final String DESCRIPTION = "description";
static final String KIND = "kind";
static final String LABELS = "labels";
static final String NAME = "name";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,13 @@
* @author jeff.cantrill
*/
public interface IProjectRequest extends IResource {

void setDisplayName(String name);

String getDisplayName();

void setDescription(String name);

String getDescription();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright (c) 2015 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.
******************************************************************************/
package com.openshift.internal.restclient.model.v1;

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


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

import com.openshift.internal.restclient.model.project.OpenshiftProjectRequest;
import com.openshift.internal.restclient.model.properties.ResourcePropertiesRegistry;
import com.openshift.restclient.IClient;
import com.openshift.restclient.ResourceKind;
import com.openshift.restclient.model.project.IProjectRequest;
import com.openshift.restclient.utils.Samples;

/**
* Test to validate the lookup paths are correct for the version
* @author Jeff Cantrill
*/
public class ProjectRequestTest{

private static final String VERSION = "v1";
private IProjectRequest request;

@Before
public void setUp(){
IClient client = mock(IClient.class);
ModelNode node = ModelNode.fromJSONString(Samples.V1_PROJECT_REQUEST.getContentAsString());
request = new OpenshiftProjectRequest(node, client, ResourcePropertiesRegistry.getInstance().get(VERSION, ResourceKind.PROJECT_REQUEST));
}

@Test
public void setDisplayName() {
request.setDisplayName("the other display name");
assertEquals("the other display name", request.getDisplayName());
}

@Test
public void testGetDisplayName() {
assertEquals("the display name", request.getDisplayName());
}

@Test
public void testGetDescription() {
assertEquals("The project description", request.getDescription());
}

@Test
public void testSetDescription() {
request.setDescription("The other project description");
assertEquals("The other project description", request.getDescription());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright (c) 2015 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.
******************************************************************************/
package com.openshift.internal.restclient.model.v1beta3;

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


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

import com.openshift.internal.restclient.model.project.OpenshiftProjectRequest;
import com.openshift.internal.restclient.model.properties.ResourcePropertiesRegistry;
import com.openshift.restclient.IClient;
import com.openshift.restclient.ResourceKind;
import com.openshift.restclient.model.project.IProjectRequest;
import com.openshift.restclient.utils.Samples;

/**
* Test to validate the lookup paths are correct for the version
* @author Jeff Cantrill
*/
public class ProjectRequestTest{

private static final String VERSION = "v1beta3";
private IProjectRequest request;

@Before
public void setUp(){
IClient client = mock(IClient.class);
ModelNode node = ModelNode.fromJSONString(Samples.V1BETA3_PROJECT_REQUEST.getContentAsString());
request = new OpenshiftProjectRequest(node, client, ResourcePropertiesRegistry.getInstance().get(VERSION, ResourceKind.PROJECT_REQUEST));
}

@Test
public void setDisplayName() {
request.setDisplayName("the other display name");
assertEquals("the other display name", request.getDisplayName());
}

@Test
public void testGetDisplayName() {
assertEquals("the display name", request.getDisplayName());
}

@Test
public void testGetDescription() {
assertEquals("The project description", request.getDescription());
}

@Test
public void testSetDescription() {
request.setDescription("The other project description");
assertEquals("The other project description", request.getDescription());
}
}
2 changes: 2 additions & 0 deletions src/test/java/com/openshift/restclient/utils/Samples.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public enum Samples {
V1BETA3_BUILD("openshift3/v1beta3_build.json"),
V1BETA3_POD("openshift3/v1beta3_pod.json"),
V1BETA3_PROJECT("openshift3/v1beta3_project.json"),
V1BETA3_PROJECT_REQUEST("openshift3/v1beta3_project_request.json"),
V1BETA3_REPLICATION_CONTROLLER("openshift3/v1beta3_replication_controller.json"),
V1BETA3_ROUTE("openshift3/v1beta3_route.json"),
V1BETA3_ROUTE_WO_TLS("openshift3/v1beta3_route_wo_tls.json"),
Expand All @@ -56,6 +57,7 @@ public enum Samples {
V1_BUILD("openshift3/v1_build.json"),
V1_POD("openshift3/v1_pod.json"),
V1_PROJECT("openshift3/v1_project.json"),
V1_PROJECT_REQUEST("openshift3/v1_project_request.json"),
V1_REPLICATION_CONTROLLER("openshift3/v1_replication_controller.json"),
V1_ROUTE("openshift3/v1_route.json"),
V1_ROUTE_WO_TLS("openshift3/v1_route_wo_tls.json"),
Expand Down
9 changes: 9 additions & 0 deletions src/test/resources/samples/openshift3/v1_project_request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"kind": "ProjectRequest",
"apiVersion": "v1",
"metadata": {
"name": "test",
},
"displayName": "the display name",
"description": "The project description"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"kind": "ProjectRequest",
"apiVersion": "v1beta3",
"metadata": {
"name": "test",
},
"displayName": "the display name",
"description": "The project description"
}