Skip to content

Commit

Permalink
[ISSUE apache#858] Add test code for this module [eventmesh-security-…
Browse files Browse the repository at this point in the history
…plugin] (apache#2502)

* add test case

* fix build error

* fix build error

* refactor test code

* remove zookeeper log

* refactor test path

* add apache license header

Co-authored-by: jonyangx <[email protected]>
  • Loading branch information
jonyangx and jonyangx authored Dec 14, 2022
1 parent 512728e commit 8d1be6c
Show file tree
Hide file tree
Showing 18 changed files with 687 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.eventmesh.acl.impl;

import org.apache.eventmesh.api.acl.AclService;
import org.apache.eventmesh.api.exception.AclException;

import java.util.Properties;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

public class AclServiceImplTest {

private static AclService service;

@BeforeClass
public static void beforeClass() {
service = new AclServiceImpl();
}

@Test
public void testInit() {
try {
service.init();
} catch (AclException e) {
Assert.fail(e.getMessage());
}
}

@Test
public void testStart() {
try {
service.start();
} catch (AclException e) {
Assert.fail(e.getMessage());
}
}

@Test
public void testShutdown() {
try {
service.shutdown();
} catch (AclException e) {
Assert.fail(e.getMessage());
}
}

@Test
public void testDoAclCheckInConnect() {
try {
service.doAclCheckInConnect(new Properties());
} catch (AclException e) {
Assert.fail(e.getMessage());
}
}

@Test
public void testDoAclCheckInHeartbeat() {
try {
service.doAclCheckInHeartbeat(new Properties());
} catch (AclException e) {
Assert.fail(e.getMessage());
}
}

@Test
public void testDoAclCheckInSend() {
try {
service.doAclCheckInSend(new Properties());
} catch (AclException e) {
Assert.fail(e.getMessage());
}
}

@Test
public void testDoAclCheckInReceive() {
try {
service.doAclCheckInReceive(new Properties());
} catch (AclException e) {
Assert.fail(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,31 @@

public class ConfigurationWrapper {

private static Logger logger = LoggerFactory.getLogger("ConfigurationWrapper");
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationWrapper.class);

private static final String EVENTMESH_CONFIG_HOME = System.getProperty("confPath", System.getenv("confPath"));

public static Properties getConfig(String configFile) {
public static Properties getConfig(String configFile) throws IOException {
String configFilePath;

// get from classpath
URL resource = ConfigurationWrapper.class.getClassLoader().getResource(configFile);
URL resource = Thread.currentThread().getContextClassLoader().getResource(configFile);
if (resource != null && new File(resource.getPath()).exists()) {
configFilePath = resource.getPath();
} else {
// get from config home
configFilePath = EVENTMESH_CONFIG_HOME + File.separator + configFile;
}

logger.info("loading auth config: {}", configFilePath);
if (LOGGER.isInfoEnabled()) {
LOGGER.info("loading auth config: {}", configFilePath);
}

Properties properties = new Properties();
try {
properties.load(new BufferedReader(new FileReader(configFilePath)));
} catch (IOException e) {
throw new IllegalArgumentException(
String.format("Cannot load RocketMQ configuration file from :%s", configFilePath));
try (BufferedReader br = new BufferedReader(new FileReader(configFilePath))) {
properties.load(br);
}

return properties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* AclException
*/
public class AclException extends RuntimeException {
private static final long serialVersionUID = -8030697611105117189L;

public AclException(String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

public class AuthException extends RuntimeException {

private static final long serialVersionUID = 7040545308620024091L;

public AuthException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.eventmesh.api.acl;

import org.apache.eventmesh.api.exception.AclException;

import java.util.Properties;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

public class AclServiceTest {

private static class DemoAclService implements AclService {

@Override
public void init() throws AclException {

}

@Override
public void start() throws AclException {

}

@Override
public void shutdown() throws AclException {

}

@Override
public void doAclCheckInConnect(Properties aclProperties) throws AclException {

}

@Override
public void doAclCheckInHeartbeat(Properties aclProperties) throws AclException {

}

@Override
public void doAclCheckInSend(Properties aclProperties) throws AclException {

}

@Override
public void doAclCheckInReceive(Properties aclProperties) throws AclException {

}
}

private static AclService service;

@BeforeClass
public static void beforeClass() {
service = new DemoAclService();
}

@Test
public void testInit() {
try {
service.init();
} catch (AclException e) {
Assert.fail(e.getMessage());
}
}

@Test
public void testStart() {
try {
service.start();
} catch (AclException e) {
Assert.fail(e.getMessage());
}
}

@Test
public void testShutdown() {
try {
service.shutdown();
} catch (AclException e) {
Assert.fail(e.getMessage());
}
}

@Test
public void testDoAclCheckInConnect() {
try {
service.doAclCheckInConnect(new Properties());
} catch (AclException e) {
Assert.fail(e.getMessage());
}
}

@Test
public void testDoAclCheckInHeartbeat() {
try {
service.doAclCheckInHeartbeat(new Properties());
} catch (AclException e) {
Assert.fail(e.getMessage());
}
}

@Test
public void testDoAclCheckInSend() {
try {
service.doAclCheckInSend(new Properties());
} catch (AclException e) {
Assert.fail(e.getMessage());
}
}

@Test
public void testDoAclCheckInReceive() {
try {
service.doAclCheckInReceive(new Properties());
} catch (AclException e) {
Assert.fail(e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.eventmesh.api.auth;

import org.apache.eventmesh.api.exception.AuthException;

import java.util.Map;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

public class AuthServiceTest {

private static class DemoAuthService implements AuthService {

@Override
public void init() throws AuthException {

}

@Override
public void start() throws AuthException {

}

@Override
public void shutdown() throws AuthException {

}

@Override
public Map<String, String> getAuthParams() throws AuthException {
return null;
}
}

private static AuthService service;

@BeforeClass
public static void beforeClass() {
service = new DemoAuthService();
}

@Test
public void testInit() {
try {
service.init();
} catch (AuthException e) {
Assert.fail(e.getMessage());
}
}

@Test
public void testStart() {
try {
service.start();
} catch (AuthException e) {
Assert.fail(e.getMessage());
}
}

@Test
public void testShutdown() {
try {
service.shutdown();
} catch (AuthException e) {
Assert.fail(e.getMessage());
}
}

@Test
public void testGetAuthParams() {
try {
Map<String, String> authParams = service.getAuthParams();
Assert.assertNull(authParams);
} catch (AuthException e) {
Assert.fail(e.getMessage());
}
}
}
Loading

0 comments on commit 8d1be6c

Please sign in to comment.