forked from fabric8io/docker-maven-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes fabric8io#960 Property placeholders are not interpolated when t…
…hey are only thing in XML Somehow these ${...} parameters are not being picked up by maven properly when used solely without any suffix string literal, the maven parameter string comes off as NULL. So adding a workaround for this. We'll use +${...} as a parameter which would be handled by dmp afterwards
- Loading branch information
1 parent
73433ff
commit 992ed24
Showing
4 changed files
with
165 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
src/test/java/io/fabric8/maven/docker/config/RunImageConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* Copyright 2015-2016 Red Hat, Inc. | ||
* | ||
* Licensed 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 io.fabric8.maven.docker.config; | ||
|
||
import org.apache.commons.lang3.SerializationUtils; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.*; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class RunImageConfigurationTest { | ||
private RunImageConfiguration runImageConfiguration; | ||
|
||
@Test | ||
public void testEnv() { | ||
Map<String, String> envMap = new HashMap<>(); | ||
|
||
envMap.put("ADDR_TYPE_1", "${docker.container.consul.ip}:8500"); | ||
envMap.put("ADDR_TYPE_2", "+${docker.container.consul.ip}"); | ||
|
||
runImageConfiguration = new RunImageConfiguration.Builder() | ||
.env(envMap) | ||
.build(); | ||
|
||
Assert.assertNotNull(runImageConfiguration); | ||
Assert.assertNotNull(runImageConfiguration.getEnv()); | ||
Assert.assertEquals("${docker.container.consul.ip}:8500", runImageConfiguration.getEnv().get("ADDR_TYPE_1")); | ||
Assert.assertEquals("+${docker.container.consul.ip}", runImageConfiguration.getEnv().get("ADDR_TYPE_2")); | ||
} | ||
|
||
@Test | ||
public void testNetworkingConfig() { | ||
runImageConfiguration = new RunImageConfiguration.Builder() | ||
.network(null) | ||
.build(); | ||
Assert.assertNotNull(runImageConfiguration); | ||
Assert.assertNotNull(runImageConfiguration.getNetworkingConfig()); | ||
} | ||
|
||
@Test | ||
public void testSerialization() { | ||
runImageConfiguration = new RunImageConfiguration.Builder() | ||
.cmd("sleep infinity") | ||
.env(Collections.singletonMap("foo", "bar")) | ||
.domainname("https://fabric8.io/") | ||
.network(new NetworkConfig.Builder() | ||
.name("test-networkconfig") | ||
.aliases(Arrays.asList("alias1", "alias2")) | ||
.build()) | ||
.links(Arrays.asList("link1", "link2", "link3")) | ||
.restartPolicy(RestartPolicy.DEFAULT) | ||
.workingDir("/home/jenkins/") | ||
.dependsOn(Arrays.asList("link1")) | ||
.labels(Collections.singletonMap("foo", "bar")) | ||
.privileged(false) | ||
.imagePullPolicy(ImagePullPolicy.IfNotPresent.name()) | ||
.hostname("localhost") | ||
.build(); | ||
|
||
byte[] serializedObj = serializeObj(runImageConfiguration); | ||
Assert.assertNotNull(serializedObj); | ||
|
||
runImageConfiguration = (RunImageConfiguration)deserializeObj(serializedObj); | ||
Assert.assertNotNull(runImageConfiguration); | ||
Assert.assertEquals("sleep infinity", runImageConfiguration.getCmd().getShell()); | ||
Assert.assertEquals("bar", runImageConfiguration.getEnv().get("foo")); | ||
Assert.assertEquals("https://fabric8.io/", runImageConfiguration.getDomainname()); | ||
Assert.assertArrayEquals(new Object[] {"alias1", "alias2"}, runImageConfiguration.getNetworkingConfig().getAliases().toArray()); | ||
Assert.assertArrayEquals(new Object[] {"link1", "link2", "link3"}, runImageConfiguration.getLinks().toArray()); | ||
Assert.assertEquals(RestartPolicy.DEFAULT.getName(), runImageConfiguration.getRestartPolicy().getName()); | ||
Assert.assertEquals("/home/jenkins/", runImageConfiguration.getWorkingDir()); | ||
Assert.assertArrayEquals(new Object[] {"link1"}, runImageConfiguration.getDependsOn().toArray()); | ||
Assert.assertEquals("bar", runImageConfiguration.getLabels().get("foo")); | ||
Assert.assertFalse(runImageConfiguration.getPrivileged()); | ||
Assert.assertEquals(ImagePullPolicy.IfNotPresent.toString(), runImageConfiguration.getImagePullPolicy()); | ||
Assert.assertEquals("localhost", runImageConfiguration.getHostname()); | ||
} | ||
|
||
private byte[] serializeObj(Object aObject) { | ||
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ||
ObjectOutput out = null; | ||
try { | ||
out = new ObjectOutputStream(bos); | ||
out.writeObject(aObject); | ||
out.flush(); | ||
byte[] convertedBytes = bos.toByteArray(); | ||
return convertedBytes; | ||
} catch(IOException exception) { | ||
// Ignore | ||
} finally { | ||
try { | ||
bos.close(); | ||
} catch(IOException exception) { | ||
// Ignore | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private Object deserializeObj(byte[] bytes) { | ||
ByteArrayInputStream bis = new ByteArrayInputStream(bytes); | ||
ObjectInput in = null; | ||
try { | ||
in = new ObjectInputStream(bis); | ||
Object aObject = in.readObject(); | ||
return aObject; | ||
} catch (Exception exception) { | ||
// Ignore | ||
} finally { | ||
try { | ||
if (in != null) { | ||
in.close(); | ||
} | ||
} catch (IOException exception) { | ||
// Ignore | ||
} | ||
} | ||
return null; | ||
} | ||
} |