Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Commit

Permalink
Add tests for ExtensionRegistry and GrpcValueUtil, make CodeQL use Ja…
Browse files Browse the repository at this point in the history
…va 19 instead of 18
  • Loading branch information
auguwu committed Dec 4, 2022
1 parent 5a9be90 commit 97872e2
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 27 deletions.
39 changes: 19 additions & 20 deletions .github/workflows/CodeQuality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java-version: [17, 18]
java-version: [17, 19]
languages: [java]
#languages: [java,kotlin]
steps:
Expand All @@ -95,22 +95,21 @@ jobs:

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
qodana-jvm:
name: Qodana JVM
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Qodana Scan
uses: JetBrains/qodana-action@v2022.2.4
with:
args: --baseline,qodana.sarif.json,--property,org.noelware.charted.ignoreJavaCheck=true,--save-report

- name: Upload SARIF Results to GitHub
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ${{ runner.temp }}/qodana/results/qodana.sarif.json

# qodana-jvm:
# name: Qodana JVM
# runs-on: ubuntu-latest
# steps:
# - name: Checkout repository
# uses: actions/checkout@v3
# with:
# fetch-depth: 0
#
# - name: Qodana Scan
# uses: JetBrains/qodana-action@v2022.2.4
# with:
# args: --baseline,qodana.sarif.json,--property,org.noelware.charted.ignoreJavaCheck=true,--save-report
#
# - name: Upload SARIF Results to GitHub
# uses: github/codeql-action/upload-sarif@v2
# with:
# sarif_file: ${{ runner.temp }}/qodana/results/qodana.sarif.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ package org.noelware.analytics.gradle
import dev.floofy.utils.gradle.*
import org.gradle.api.JavaVersion

val VERSION = Version(0, 1, 1, 0, ReleaseType.Beta)
val VERSION = Version(0, 1, 2, 0, ReleaseType.Beta)
val JAVA_VERSION = JavaVersion.VERSION_17
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public Value toGrpcValue() {
info.stream().map(ThreadInfo::toGrpcValue).toList())
.build()));

return Value.newBuilder().setStructValue(struct).build();
return GrpcValueUtil.toValue(struct.build());
}
}

Expand Down Expand Up @@ -149,7 +149,7 @@ public Value toGrpcValue() {
GrpcValueUtil.toValue(
stacktrace.stream().map(this::toGrpcValue).toList()));

return GrpcValueUtil.toValue(struct);
return GrpcValueUtil.toValue(struct.build());
}

private Value toGrpcValue(StackTraceElement element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@

package org.noelware.analytics.jvm.server.util;

import com.google.protobuf.ListValue;
import com.google.protobuf.NullValue;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import com.google.protobuf.*;
import java.util.List;
import org.noelware.analytics.jvm.server.serialization.Serializable;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 🐻‍❄️🌂 analytics-jvm: Client and server implementation of Noelware Analytics in Java, supported for both Java and Kotlin
* Copyright (c) 2022 Noelware <team@noelware.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package org.noelware.analytics.tests.server;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.noelware.analytics.jvm.server.extensions.ExtensionRegistry;
import org.noelware.analytics.jvm.server.extensions.internal.DefaultExtensionRegistry;
import org.noelware.analytics.jvm.server.extensions.jvm.JvmMemoryPoolsExtension;
import org.noelware.analytics.jvm.server.extensions.jvm.JvmThreadsExtension;
import org.noelware.analytics.jvm.server.extensions.jvm.JvmVersionInfoExtension;

public class ExtensionRegistryTest {
private static final ExtensionRegistry registry = new DefaultExtensionRegistry();

@BeforeAll
public static void beforeRun() {
registry.registerAll(new JvmThreadsExtension(), new JvmMemoryPoolsExtension(), new JvmVersionInfoExtension());
}

@Test
public void test_findByClass() {
assertNull(registry.findByClass(JvmThreadsExtension.JvmThreadsData.class));
assertNotNull(registry.findByClass(JvmThreadsExtension.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 🐻‍❄️🌂 analytics-jvm: Client and server implementation of Noelware Analytics in Java, supported for both Java and Kotlin
* Copyright (c) 2022 Noelware <team@noelware.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package org.noelware.analytics.tests.server;

import static org.junit.jupiter.api.Assertions.*;

import com.google.protobuf.ListValue;
import com.google.protobuf.Struct;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.noelware.analytics.jvm.server.extensions.jvm.JvmThreadsExtension;
import org.noelware.analytics.jvm.server.util.GrpcValueUtil;

public class GrpcValueUtilTests {
@Test
public void test_ifValuesAreAcceptable() {
assertDoesNotThrow(() -> GrpcValueUtil.toValue("a string owo"));
assertDoesNotThrow(() -> GrpcValueUtil.toValue(1));
assertDoesNotThrow(() -> GrpcValueUtil.toValue(1L));
assertDoesNotThrow(() -> GrpcValueUtil.toValue(1f));
assertDoesNotThrow(() -> GrpcValueUtil.toValue(1.0));
assertDoesNotThrow(() -> GrpcValueUtil.toValue(true));
assertDoesNotThrow(() -> GrpcValueUtil.toValue(1L));
assertDoesNotThrow(() -> GrpcValueUtil.toValue(new JvmThreadsExtension().supply()));
assertDoesNotThrow(() -> GrpcValueUtil.toValue(List.of("a", "b", "c")));
assertDoesNotThrow(() -> GrpcValueUtil.toValue(ListValue.newBuilder().build()));
assertDoesNotThrow(() -> GrpcValueUtil.toValue(Struct.newBuilder().build()));

assertThrows(IllegalStateException.class, () -> {
GrpcValueUtil.toValue(new Object());
});

assertThrows(IllegalStateException.class, () -> {
GrpcValueUtil.toValue(Struct.newBuilder());
});
}
}

0 comments on commit 97872e2

Please sign in to comment.