Skip to content

Commit

Permalink
Add support for HTTP POJA feature
Browse files Browse the repository at this point in the history
  • Loading branch information
andriy-dmytruk committed Oct 21, 2024
1 parent 4c7b838 commit 64d8a23
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2017-2022 original authors
*
* 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
*
* https://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.micronaut.starter.feature.server;

import io.micronaut.core.annotation.NonNull;
import io.micronaut.starter.application.generator.GeneratorContext;
import io.micronaut.starter.build.dependencies.Dependency;
import io.micronaut.starter.options.BuildTool;
import jakarta.inject.Singleton;

@Singleton
public class HttpPoja extends AbstractMicronautServerFeature {

@Override
public String getName() {
return "http-poja";
}

@Override
public String getTitle() {
return "Plain Old Java HTTP Application";
}

@Override
public String getDescription() {
return "Add support for HTTP POJA based on Apache libraries";
}

@Override
public String getMicronautDocumentation() {
return "https://micronaut-projects.github.io/micronaut-servlet/latest/guide/index.html#httpPoja";
}

@Override
public void doApply(GeneratorContext generatorContext) {
if (generatorContext.getBuildTool() == BuildTool.MAVEN) {
generatorContext.addDependency(Dependency.builder()
.groupId("io.micronaut.servlet")
.artifactId("micronaut-http-poja-apache")
.compile());
generatorContext.addDependency(Dependency.builder()
.groupId("io.micronaut.servlet")
.artifactId("micronaut-http-poja-test")
.test());
}
}

@Override
@NonNull
public String resolveMicronautRuntime(@NonNull GeneratorContext generatorContext) {
return "http_poja";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class MavenSpec extends ApplicationContextSpec implements CommandOutputFixture {
ApplicationType.DEFAULT | ["aws-lambda", 'graalvm'] | "lambda"
ApplicationType.DEFAULT | ["tomcat-server"] | "tomcat"
ApplicationType.DEFAULT | ["jetty-server"] | "jetty"
ApplicationType.DEFAULT | ["http-poja"] | "http_poja"
ApplicationType.DEFAULT | ["netty-server"] | "netty"
ApplicationType.DEFAULT | ["undertow-server"] | "undertow"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.micronaut.starter.feature.server

import io.micronaut.starter.BeanContextSpec
import io.micronaut.starter.BuildBuilder
import io.micronaut.starter.build.BuildTestUtil
import io.micronaut.starter.build.BuildTestVerifier
import io.micronaut.starter.fixture.CommandOutputFixture
import io.micronaut.starter.options.BuildTool
import io.micronaut.starter.options.Language

class HttpPojaTestSpec extends BeanContextSpec implements CommandOutputFixture {

void 'test readme.md with feature http-poja contains links to micronaut docs'() {
when:
Map<String, String> output = generate(['http-poja'])
String readme = output["README.md"]

then:
readme
readme.contains("https://micronaut-projects.github.io/micronaut-servlet/latest/guide/index.html#httpPoja")
}

void 'test #buildTool http-poja feature for language=#language'(Language language, BuildTool buildTool) {
when:
String template = new BuildBuilder(beanContext, buildTool)
.language(language)
.features(["http-poja"])
.render()
BuildTestVerifier verifier = BuildTestUtil.verifier(buildTool, language, template)

then:
template.contains("runtime(\"http_poja\")") || template.contains("<micronaut.runtime>http_poja</micronaut.runtime>")

and: "Contains required dependencies"
buildTool != BuildTool.MAVEN
|| template.contains("micronaut-http-poja-apache") && template.contains("micronaut-http-poja-test")

where:
[language, buildTool] << [Language.values().toList(), BuildTool.values()].combinations()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ServerSpec extends ApplicationContextSpec {
"jetty-server" | 'runtime("jetty")'
"tomcat-server" | 'runtime("tomcat")'
"undertow-server" | 'runtime("undertow")'
"http-poja" | 'runtime("http_poja")'
}

@Unroll
Expand Down Expand Up @@ -79,11 +80,12 @@ class ServerSpec extends ApplicationContextSpec {
"jetty-server" | 'io.micronaut.servlet' | 'micronaut-http-server-jetty'
"tomcat-server" | 'io.micronaut.servlet' | 'micronaut-http-server-tomcat'
"undertow-server" | 'io.micronaut.servlet' | 'micronaut-http-server-undertow'
"http-poja" | 'io.micronaut.servlet' | 'micronaut-http-poja-apache'
}

void 'test there can only be one server feature'() {
when:
getFeatures(["netty-server", "jetty-server", "tomcat-server", "undertow-server"])
getFeatures(["netty-server", "jetty-server", "tomcat-server", "undertow-server", "http-poja"])

then:
def ex = thrown(IllegalArgumentException)
Expand Down

0 comments on commit 64d8a23

Please sign in to comment.