diff --git a/pom.xml b/pom.xml index daabe45c..6e488ec3 100644 --- a/pom.xml +++ b/pom.xml @@ -172,11 +172,19 @@ com.jcabi jcabi-aspects + + com.jcabi + jcabi-github + org.aspectj aspectjrt runtime + + org.glassfish + javax.json + diff --git a/src/main/java/com/thindeck/steps/ReadConfig.java b/src/main/java/com/thindeck/steps/ReadConfig.java new file mode 100644 index 00000000..bc6dcbd4 --- /dev/null +++ b/src/main/java/com/thindeck/steps/ReadConfig.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2014, Thindeck.com + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: 1) Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. 2) Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. 3) Neither the name of the thindeck.com nor + * the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.thindeck.steps; + +import com.jcabi.aspects.Immutable; +import com.jcabi.github.Github; +import com.thindeck.api.Context; +import com.thindeck.api.Step; +import java.io.IOException; + +/** + * Read repository configuration. + * + * @author Carlos Miranda (miranda.cma@gmail.com) + * @version $Id$ + * @since 0.3 + */ +@Immutable +public final class ReadConfig implements Step { + + /** + * Public ctor. + * @param ghub Github instance. + */ + @SuppressWarnings("PMD.UnusedFormalParameter") + public ReadConfig(final Github ghub) { + throw new UnsupportedOperationException("Not yet implemented."); + } + + @Override + public String name() { + return "read-config"; + } + + @Override + public void exec(final Context ctx) throws IOException { + throw new UnsupportedOperationException("exec: Not yet implemented"); + } + @Override + public void commit(final Context ctx) { + // nothing to commit + } + + @Override + public void rollback(final Context ctx) { + // nothing to rollback + } +} diff --git a/src/test/java/com/thindeck/steps/ReadConfigTest.java b/src/test/java/com/thindeck/steps/ReadConfigTest.java new file mode 100644 index 00000000..c26bdb4d --- /dev/null +++ b/src/test/java/com/thindeck/steps/ReadConfigTest.java @@ -0,0 +1,101 @@ +/** + * Copyright (c) 2014, Thindeck.com + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: 1) Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. 2) Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. 3) Neither the name of the thindeck.com nor + * the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.thindeck.steps; + +import com.google.common.base.Joiner; +import com.jcabi.github.Github; +import com.jcabi.github.Repo; +import com.jcabi.github.mock.MkGithub; +import com.jcabi.matchers.XhtmlMatchers; +import com.thindeck.api.Context; +import com.thindeck.api.Step; +import com.thindeck.api.mock.MkContext; +import javax.json.Json; +import org.hamcrest.MatcherAssert; +import org.junit.Test; +import org.xembly.Directives; + +/** + * Test case for {@link ReadConfig}. + * + * @author Carlos Miranda (miranda.cma@gmail.com) + * @version $Id$ + * @since 0.3 + */ +public final class ReadConfigTest { + + /** + * Fetch repo configuration and update memo accordingly. + * @throws Exception If something goes wrong + * @todo #291 This test is currently ignored because ReadConfig is not yet + * implemented. Let's implement it, and have it read the info from the + * .thindeck.yml file of the repository root and update the Memo XML. See + * https://github.com/yegor256/thindeck/issues/291 for further details. + */ + @Test + @org.junit.Ignore + public void fetchesRepoConfigAndUpdatesMemo() throws Exception { + final Github ghub = new MkGithub("thindeck"); + final Repo repo = ghub.repos().create( + Json.createObjectBuilder() + .add("name", "test") + .build() + ); + final String config = Joiner.on('\n').join( + "domains: [\"example.com\", \"test.example.com\"]", + "ports: [80, 443]" + ); + repo.contents().create( + Json.createObjectBuilder() + .add("path", ".thindeck.yml") + .add("message", "Thindeck config") + .add("content", config) + .build() + ); + final Context ctx = new MkContext(); + ctx.memo().update( + new Directives() + .add("/memo") + .add("/repo") + .add("/uri").set("git@github.com:thindeck/test.git") + ); + final Step step = new ReadConfig(ghub); + step.exec(ctx); + MatcherAssert.assertThat( + ctx.memo().read(), + XhtmlMatchers.hasXPaths( + "//memo/domains/domain[.='example.com']", + "//memo/domains/domain[.='test.example.com']", + "//memo/ports/port[.='80']", + "//memo/ports/port[.='443']" + ) + ); + } +}