Hello World service for NONRTRIC - Unit Tests Added 96/12196/2
authorambrishest <ambrish.singh@est.tech>
Thu, 7 Dec 2023 08:33:45 +0000 (08:33 +0000)
committerambrishest <ambrish.singh@est.tech>
Fri, 8 Dec 2023 14:47:44 +0000 (14:47 +0000)
Issue-ID: NONRTRIC-944
Change-Id: I59122a202746587a34d461ef84fd331bf7c5a73e
Signed-off-by: ambrishest <ambrish.singh@est.tech>
21 files changed:
test/cr/cr-build-start.sh
test/mrstub/mrstub-build-start.sh
test/prodstub/prod-stub-build-start.sh
test/servicestub/.gitignore [new file with mode: 0644]
test/servicestub/Dockerfile [new file with mode: 0644]
test/servicestub/README.md [new file with mode: 0644]
test/servicestub/build.sh [new file with mode: 0644]
test/servicestub/container-tag.yaml [new file with mode: 0644]
test/servicestub/docker-compose.yml [new file with mode: 0644]
test/servicestub/hello-world-chart/.helmignore [new file with mode: 0644]
test/servicestub/hello-world-chart/Chart.yaml [new file with mode: 0644]
test/servicestub/hello-world-chart/templates/_helpers.tpl [new file with mode: 0644]
test/servicestub/hello-world-chart/templates/deployment.yaml [new file with mode: 0644]
test/servicestub/hello-world-chart/templates/service.yaml [new file with mode: 0644]
test/servicestub/hello-world-chart/templates/tests/test-connection.yaml [new file with mode: 0644]
test/servicestub/hello-world-chart/values.yaml [new file with mode: 0644]
test/servicestub/pom.xml [new file with mode: 0644]
test/servicestub/service-stub-build-start.sh [new file with mode: 0644]
test/servicestub/src/main/java/org/oran/helloworld/HelloWorldApplication.java [new file with mode: 0644]
test/servicestub/src/main/java/org/oran/helloworld/rest/HelloWorldController.java [new file with mode: 0644]
test/servicestub/src/test/java/org/oran/helloworld/rest/HelloWorldControllerTest.java [new file with mode: 0644]

index 03e9ed2..000cd52 100755 (executable)
@@ -19,6 +19,6 @@
 
 #Builds the callback receiver container and starts it in interactive mode
 
-docker build --build-arg NEXUS_PROXY_REPO=nexus3.onap.org:10001/ -t callback-receiver .
+docker build -t callback-receiver .
 
 docker run --rm -it -p 8090:8090 -p 8091:8091 --name cr callback-receiver
index 1874f97..c245172 100755 (executable)
@@ -19,6 +19,6 @@
 
 #Builds the mrstub container and starts it in interactive mode
 
-docker build --build-arg NEXUS_PROXY_REPO=nexus3.onap.org:10001/  -t mrstub .
+docker build -t mrstub .
 
 docker run --rm --name=dmaap-mr -it -p 3904:3904 -p 3905:3905 -v "$PWD/cert:/usr/src/app/cert" mrstub
index 89cc967..d10626e 100755 (executable)
@@ -22,6 +22,6 @@
 NAME="producer-stub-test"
 IMAGE_NAME="producer-stub-test-image"
 
-docker build --build-arg NEXUS_PROXY_REPO=nexus3.onap.org:10001/ -t $IMAGE_NAME .
+docker build -t $IMAGE_NAME .
 
 docker run --rm -it -p 8992:8092 -p 8993:8093 --name $NAME $IMAGE_NAME
diff --git a/test/servicestub/.gitignore b/test/servicestub/.gitignore
new file mode 100644 (file)
index 0000000..5ff6309
--- /dev/null
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git a/test/servicestub/Dockerfile b/test/servicestub/Dockerfile
new file mode 100644 (file)
index 0000000..fb942d8
--- /dev/null
@@ -0,0 +1,47 @@
+#==================================================================================
+#   Copyright (C) 2023: OpenInfra Foundation Europe
+#
+#   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.
+#
+#   This source code is part of the near-RT RIC (RAN Intelligent Controller)
+#   platform project (RICP).
+#==================================================================================
+
+
+# Use Maven image with OpenJDK 17 for the build stage
+FROM maven:3.8.5-openjdk-17 AS maven_build
+
+# Copy Maven project files
+COPY pom.xml /tmp/
+COPY src /tmp/src/
+
+# Set working directory
+WORKDIR /tmp/
+
+# Build the Maven project
+RUN mvn package
+
+# Use a separate image with OpenJDK 17 for the runtime stage
+FROM openjdk:17-jdk-slim
+
+# Expose port 8080
+EXPOSE 8080
+
+# Set the working directory
+WORKDIR /app
+
+# Copy the JAR file from the maven_build stage to the runtime stage
+COPY --from=maven_build /tmp/target/hello-world-0.1.0.jar /app/hello-world-0.1.0.jar
+
+# Command to run the application
+CMD ["java", "-jar", "hello-world-0.1.0.jar"]
diff --git a/test/servicestub/README.md b/test/servicestub/README.md
new file mode 100644 (file)
index 0000000..601e52a
--- /dev/null
@@ -0,0 +1,37 @@
+# Hello World Service Stub\r
+\r
+This repository contains a Spring Boot application serving a Hello World endpoint. The application can be built and \r
+run using the provided script - ``service-stub-build-start.sh``.\r
+\r
+## Prerequisites\r
+\r
+- Docker installed on your machine.\r
+\r
+## Building and Running the Application\r
+Run the script:\r
+\r
+```bash\r
+  ./service-stub-build-start.sh\r
+```\r
+\r
+The script will build a Docker image and run a container with the Hello World service. After the container starts, \r
+wait for a few seconds to ensure the Spring Boot application is fully initialized. Next, it will make an HTTP request to the \r
+Hello World endpoint and display the response:\r
+\r
+```bash\r
+  response=$(curl -s http://localhost:8080/helloworld/sme)\r
+  echo "Response from the Hello World endpoint:"\r
+  echo "$response"\r
+```\r
+\r
+To stop and remove the Docker container:\r
+\r
+```bash\r
+  docker stop service-stub-hello-world-test\r
+  docker rm service-stub-hello-world-test\r
+```\r
+\r
+## Additional Information\r
+\r
+- The Hello World endpoint is available at http://localhost:8080/helloworld/sme.\r
+\r
diff --git a/test/servicestub/build.sh b/test/servicestub/build.sh
new file mode 100644 (file)
index 0000000..bb0ff80
--- /dev/null
@@ -0,0 +1,96 @@
+#!/bin/bash
+
+#  ============LICENSE_START===============================================
+#  Copyright (C) 2023: OpenInfra Foundation Europe.
+#  ========================================================================
+#  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.
+#  ============LICENSE_END=================================================
+#
+
+# Build image from Dockerfile with/without custom image tag
+# Optionally push to external image repo
+
+print_usage() {
+    echo "Usage: build.sh no-push|<docker-hub-repo-name> [<image-tag>]"
+    exit 1
+}
+
+if [ $# -ne 1 ] && [ $# -ne 2 ]; then
+    print_usage
+fi
+
+IMAGE_NAME="nonrtric-hello-world"
+IMAGE_TAG="latest"
+REPO=""
+if [ $1 == "no-push" ]; then
+    echo "Only local image build"
+else
+    REPO=$1
+    echo "Attempt to push built image to: "$REPO
+fi
+
+shift
+while [ $# -ne 0 ]; do
+    if [ $1 == "--tag" ]; then
+        shift
+        if [ -z "$1" ]; then
+            print_usage
+        fi
+        IMAGE_TAG=$1
+        echo "Setting image tag to: "$IMAGE_TAG
+        shift
+    else
+        echo "Unknown parameter: $1"
+        print_usage
+    fi
+done
+
+IMAGE=$IMAGE_NAME:$IMAGE_TAG
+
+export DOCKER_DEFAULT_PLATFORM=linux/amd64
+CURRENT_PLATFORM=$(docker system info --format '{{.OSType}}/{{.Architecture}}')
+if [ $CURRENT_PLATFORM != $DOCKER_DEFAULT_PLATFORM ]; then
+    echo "Image may not work on the current platform: $CURRENT_PLATFORM, only platform $DOCKER_DEFAULT_PLATFORM supported"
+fi
+
+echo "Building image $IMAGE"
+docker build -t $IMAGE_NAME:$IMAGE_TAG .
+if [ $? -ne 0 ]; then
+    echo "BUILD FAILED"
+    exit 1
+fi
+echo "BUILD OK"
+
+if [ "$REPO" != "" ]; then
+    echo "Tagging image"
+    NEW_IMAGE=$REPO/$IMAGE_NAME:$IMAGE_TAG
+    docker tag $IMAGE $NEW_IMAGE
+    if [ $? -ne 0 ]; then
+        echo "RE-TAGGING FAILED"
+        exit 1
+    fi
+    echo "RE-TAG OK"
+
+    echo "Pushing image $NEW_IMAGE"
+    docker push $NEW_IMAGE
+    if [ $? -ne 0 ]; then
+        echo "PUSHED FAILED"
+        echo " Perhaps not logged into docker-hub repo $REPO?"
+        exit 1
+    fi
+    IMAGE=$NEW_IMAGE
+    echo "PUSH OK"
+fi
+
+echo "IMAGE OK: $IMAGE"
+echo "DONE"
diff --git a/test/servicestub/container-tag.yaml b/test/servicestub/container-tag.yaml
new file mode 100644 (file)
index 0000000..d911388
--- /dev/null
@@ -0,0 +1,25 @@
+# -
+#   ========================LICENSE_START=================================
+#   O-RAN-SC
+#   %%
+#   Copyright (C) 2023: OpenInfra Foundation Europe.
+#   %%
+#   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.
+#   ========================LICENSE_END===================================
+#
+
+# The Jenkins job requires a tag to build the Docker image.
+# By default this file is in the docker build directory,
+# but the location can configured in the JJB template.
+---
+tag: 0.1.0
diff --git a/test/servicestub/docker-compose.yml b/test/servicestub/docker-compose.yml
new file mode 100644 (file)
index 0000000..b137ec1
--- /dev/null
@@ -0,0 +1,29 @@
+# -
+#   ========================LICENSE_START=================================
+#   O-RAN-SC
+#   %%
+#   Copyright (C) 2023: OpenInfra Foundation Europe
+#   %%
+#   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.
+#   ========================LICENSE_END===================================
+#
+
+version: "3.0"
+
+services:
+  hello-world:
+    build: 
+      context: ./
+      dockerfile: Dockerfile
+    ports:
+      - 8080:8080
\ No newline at end of file
diff --git a/test/servicestub/hello-world-chart/.helmignore b/test/servicestub/hello-world-chart/.helmignore
new file mode 100644 (file)
index 0000000..0e8a0eb
--- /dev/null
@@ -0,0 +1,23 @@
+# Patterns to ignore when building packages.
+# This supports shell glob matching, relative path matching, and
+# negation (prefixed with !). Only one pattern per line.
+.DS_Store
+# Common VCS dirs
+.git/
+.gitignore
+.bzr/
+.bzrignore
+.hg/
+.hgignore
+.svn/
+# Common backup files
+*.swp
+*.bak
+*.tmp
+*.orig
+*~
+# Various IDEs
+.project
+.idea/
+*.tmproj
+.vscode/
diff --git a/test/servicestub/hello-world-chart/Chart.yaml b/test/servicestub/hello-world-chart/Chart.yaml
new file mode 100644 (file)
index 0000000..3f5d200
--- /dev/null
@@ -0,0 +1,44 @@
+# -
+#   ========================LICENSE_START=================================
+#   O-RAN-SC
+#   %%
+#   Copyright (C) 2023: OpenInfra Foundation Europe
+#   %%
+#   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.
+#   ========================LICENSE_END===================================
+#
+
+apiVersion: v2
+name: hello-world-chart
+description: A Helm chart for NONRTRIC Hello World
+
+# A chart can be either an 'application' or a 'library' chart.
+#
+# Application charts are a collection of templates that can be packaged into versioned archives
+# to be deployed.
+#
+# Library charts provide useful utilities or functions for the chart developer. They're included as
+# a dependency of application charts to inject those utilities and functions into the rendering
+# pipeline. Library charts do not define any templates and therefore cannot be deployed.
+type: application
+
+# This is the chart version. This version number should be incremented each time you make changes
+# to the chart and its templates, including the app version.
+# Versions are expected to follow Semantic Versioning (https://semver.org/)
+version: 0.1.0
+
+# This is the version number of the application being deployed. This version number should be
+# incremented each time you make changes to the application. Versions are not expected to
+# follow Semantic Versioning. They should reflect the version the application is using.
+# It is recommended to use it with quotes.
+appVersion: "0.1.0"
diff --git a/test/servicestub/hello-world-chart/templates/_helpers.tpl b/test/servicestub/hello-world-chart/templates/_helpers.tpl
new file mode 100644 (file)
index 0000000..5759827
--- /dev/null
@@ -0,0 +1,62 @@
+{{/*
+Expand the name of the chart.
+*/}}
+{{- define "hello-world-chart.name" -}}
+{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
+{{- end }}
+
+{{/*
+Create a default fully qualified app name.
+We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
+If release name contains chart name it will be used as a full name.
+*/}}
+{{- define "hello-world-chart.fullname" -}}
+{{- if .Values.fullnameOverride }}
+{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
+{{- else }}
+{{- $name := default .Chart.Name .Values.nameOverride }}
+{{- if contains $name .Release.Name }}
+{{- .Release.Name | trunc 63 | trimSuffix "-" }}
+{{- else }}
+{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
+{{- end }}
+{{- end }}
+{{- end }}
+
+{{/*
+Create chart name and version as used by the chart label.
+*/}}
+{{- define "hello-world-chart.chart" -}}
+{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
+{{- end }}
+
+{{/*
+Common labels
+*/}}
+{{- define "hello-world-chart.labels" -}}
+helm.sh/chart: {{ include "hello-world-chart.chart" . }}
+{{ include "hello-world-chart.selectorLabels" . }}
+{{- if .Chart.AppVersion }}
+app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
+{{- end }}
+app.kubernetes.io/managed-by: {{ .Release.Service }}
+{{- end }}
+
+{{/*
+Selector labels
+*/}}
+{{- define "hello-world-chart.selectorLabels" -}}
+app.kubernetes.io/name: {{ include "hello-world-chart.name" . }}
+app.kubernetes.io/instance: {{ .Release.Name }}
+{{- end }}
+
+{{/*
+Create the name of the service account to use
+*/}}
+{{- define "hello-world-chart.serviceAccountName" -}}
+{{- if .Values.serviceAccount.create }}
+{{- default (include "hello-world-chart.fullname" .) .Values.serviceAccount.name }}
+{{- else }}
+{{- default "default" .Values.serviceAccount.name }}
+{{- end }}
+{{- end }}
diff --git a/test/servicestub/hello-world-chart/templates/deployment.yaml b/test/servicestub/hello-world-chart/templates/deployment.yaml
new file mode 100644 (file)
index 0000000..57f5357
--- /dev/null
@@ -0,0 +1,43 @@
+# -
+#   ========================LICENSE_START=================================
+#   O-RAN-SC
+#   %%
+#   Copyright (C) 2023: OpenInfra Foundation Europe
+#   %%
+#   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.
+#   ========================LICENSE_END===================================
+#
+
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ include "hello-world-chart.fullname" . }}
+  labels:
+    {{- include "hello-world-chart.labels" . | nindent 4 }}
+spec:
+  replicas: {{ .Values.replicaCount }}
+  selector:
+    matchLabels:
+      {{- include "hello-world-chart.selectorLabels" . | nindent 8 }}
+  template:
+    metadata:
+      labels:
+        {{- include "hello-world-chart.selectorLabels" . | nindent 12 }}
+    spec:
+      containers:
+        - name: {{ .Chart.Name }}
+          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
+          ports:
+            - name: http
+              containerPort: {{ .Values.service.port }}
+
diff --git a/test/servicestub/hello-world-chart/templates/service.yaml b/test/servicestub/hello-world-chart/templates/service.yaml
new file mode 100644 (file)
index 0000000..fdd9144
--- /dev/null
@@ -0,0 +1,37 @@
+# -
+#   ========================LICENSE_START=================================
+#   O-RAN-SC
+#   %%
+#   Copyright (C) 2023: OpenInfra Foundation Europe
+#   %%
+#   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.
+#   ========================LICENSE_END===================================
+#
+
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ include "hello-world-chart.fullname" . }}
+  labels:
+    {{- include "hello-world-chart.labels" . | nindent 4 }}
+spec:
+  type: {{ .Values.service.type }}
+  ports:
+    - port: {{ .Values.service.port }}
+      targetPort: http
+      protocol: TCP
+      name: http
+      nodePort: 30951
+  selector:
+    {{- include "hello-world-chart.selectorLabels" . | nindent 4 }}
+
diff --git a/test/servicestub/hello-world-chart/templates/tests/test-connection.yaml b/test/servicestub/hello-world-chart/templates/tests/test-connection.yaml
new file mode 100644 (file)
index 0000000..a8b1698
--- /dev/null
@@ -0,0 +1,35 @@
+# -
+#   ========================LICENSE_START=================================
+#   O-RAN-SC
+#   %%
+#   Copyright (C) 2023: OpenInfra Foundation Europe
+#   %%
+#   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.
+#   ========================LICENSE_END===================================
+#
+
+apiVersion: v1
+kind: Pod
+metadata:
+  name: "{{ include "hello-world-chart.fullname" . }}-test-connection"
+  labels:
+    {{- include "hello-world-chart.labels" . | nindent 4 }}
+  annotations:
+    "helm.sh/hook": test
+spec:
+  containers:
+    - name: wget
+      image: busybox
+      command: ['wget']
+      args: ['{{ include "hello-world-chart.fullname" . }}:{{ .Values.service.port }}']
+  restartPolicy: Never
diff --git a/test/servicestub/hello-world-chart/values.yaml b/test/servicestub/hello-world-chart/values.yaml
new file mode 100644 (file)
index 0000000..8856b1c
--- /dev/null
@@ -0,0 +1,29 @@
+# -
+#   ========================LICENSE_START=================================
+#   O-RAN-SC
+#   %%
+#   Copyright (C) 2023: OpenInfra Foundation Europe
+#   %%
+#   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.
+#   ========================LICENSE_END===================================
+#
+
+image:
+  repository: nonrtric-hello-world
+  tag: latest
+
+service:
+  name: hello-world
+  type: NodePort
+  port: 8080
+
diff --git a/test/servicestub/pom.xml b/test/servicestub/pom.xml
new file mode 100644 (file)
index 0000000..be7a791
--- /dev/null
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+* ========================LICENSE_START=================================
+* O-RAN-SC
+* %%
+* Copyright (C) 2023 OpenInfra Foundation Europe.
+* %%
+* 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.
+* ========================LICENSE_END===================================
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.o-ran-sc.nonrtric.plt</groupId>
+    <artifactId>hello-world</artifactId>
+    <version>0.1.0</version>
+
+    <properties>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>3.1.0</version>
+    </parent>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file
diff --git a/test/servicestub/service-stub-build-start.sh b/test/servicestub/service-stub-build-start.sh
new file mode 100644 (file)
index 0000000..b798e86
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+# -
+#   ========================LICENSE_START=================================
+#   O-RAN-SC
+#   %%
+#   Copyright (C) 2023: OpenInfra Foundation Europe.
+#   %%
+#   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.
+#   ========================LICENSE_END===================================
+#
+
+NAME="service-stub-hello-world-test"
+IMAGE_NAME="nonrtric-hello-world"
+
+docker build -t $IMAGE_NAME:latest .
+
+docker run --rm -d -p 8080:8080 --name $NAME $IMAGE_NAME
+
+sleep 10
+
+echo "Make an HTTP request to the Hello World endpoint and display the response"
+response=$(curl -s http://localhost:8080/helloworld/sme)
+
+echo "Response from the /helloworld/sme endpoint: "
+echo "$response"
+
+response2=$(curl -s http://localhost:8080/helloworld)
+echo "Response from the /helloworld endpoint: "
+echo "$response2"
diff --git a/test/servicestub/src/main/java/org/oran/helloworld/HelloWorldApplication.java b/test/servicestub/src/main/java/org/oran/helloworld/HelloWorldApplication.java
new file mode 100644 (file)
index 0000000..c1fe5e9
--- /dev/null
@@ -0,0 +1,31 @@
+/*-\r
+ * ========================LICENSE_START=================================\r
+ * O-RAN-SC\r
+ * %%\r
+ * Copyright (C) 2023 OpenInfra Foundation Europe.\r
+ * %%\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ========================LICENSE_END===================================\r
+ */\r
+\r
+package org.oran.helloworld;\r
+\r
+import org.springframework.boot.SpringApplication;\r
+import org.springframework.boot.autoconfigure.SpringBootApplication;\r
+\r
+@SpringBootApplication(scanBasePackages = "org.oran.helloworld")\r
+public class HelloWorldApplication {\r
+    public static void main(String[] args) {\r
+        SpringApplication.run(HelloWorldApplication.class, args);\r
+    }\r
+}\r
diff --git a/test/servicestub/src/main/java/org/oran/helloworld/rest/HelloWorldController.java b/test/servicestub/src/main/java/org/oran/helloworld/rest/HelloWorldController.java
new file mode 100644 (file)
index 0000000..994e151
--- /dev/null
@@ -0,0 +1,38 @@
+/*-\r
+ * ========================LICENSE_START=================================\r
+ * O-RAN-SC\r
+ * %%\r
+ * Copyright (C) 2023 OpenInfra Foundation Europe.\r
+ * %%\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ========================LICENSE_END===================================\r
+ */\r
+\r
+package org.oran.helloworld.rest;\r
+\r
+import org.springframework.web.bind.annotation.RequestMapping;\r
+import org.springframework.web.bind.annotation.RestController;\r
+\r
+@RestController\r
+@RequestMapping("/helloworld")\r
+public class HelloWorldController {\r
+\r
+    @RequestMapping("")\r
+    public String helloWorld() {\r
+        return "Hello World from service stub\n";\r
+    }\r
+    @RequestMapping("/sme")\r
+    public String helloWorldSme() {\r
+        return "Hello World from SME\n";\r
+    }\r
+}\r
diff --git a/test/servicestub/src/test/java/org/oran/helloworld/rest/HelloWorldControllerTest.java b/test/servicestub/src/test/java/org/oran/helloworld/rest/HelloWorldControllerTest.java
new file mode 100644 (file)
index 0000000..0d29c8b
--- /dev/null
@@ -0,0 +1,59 @@
+/*-\r
+ * ========================LICENSE_START=================================\r
+ * O-RAN-SC\r
+ * %%\r
+ * Copyright (C) 2023 OpenInfra Foundation Europe.\r
+ * %%\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ========================LICENSE_END===================================\r
+ */\r
+\r
+package org.oran.helloworld.rest;\r
+\r
+import org.junit.jupiter.api.Test;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;\r
+import org.springframework.boot.test.mock.mockito.MockBean;\r
+import org.springframework.test.web.servlet.MockMvc;\r
+\r
+import static org.mockito.Mockito.when;\r
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;\r
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;\r
+\r
+@WebMvcTest(HelloWorldController.class)\r
+public class HelloWorldControllerTest {\r
+\r
+    @Autowired\r
+    private MockMvc mockMvc;\r
+\r
+    @MockBean\r
+    private HelloWorldController helloWorldController;\r
+\r
+    @Test\r
+    public void testHelloWorldEndpoint() throws Exception {\r
+        when(helloWorldController.helloWorld()).thenReturn("Hello World from service stub\n");\r
+\r
+        mockMvc.perform(get("/helloworld"))\r
+            .andExpect(status().isOk())\r
+            .andExpect(content().string("Hello World from service stub\n"));\r
+    }\r
+\r
+    @Test\r
+    public void testHelloWorldSmeEndpoint() throws Exception {\r
+        when(helloWorldController.helloWorldSme()).thenReturn("Hello World from SME\n");\r
+\r
+        mockMvc.perform(get("/helloworld/sme"))\r
+            .andExpect(status().isOk())\r
+            .andExpect(content().string("Hello World from SME\n"));\r
+    }\r
+}\r