-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
190 changed files
with
6,920 additions
and
5,001 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
io.openems.backend.metadata.file/.settings/org.eclipse.core.resources.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
eclipse.preferences.version=1 | ||
encoding//test/io/openems/backend/metadata/file/provider/FileTest.java=UTF-8 | ||
encoding/bnd.bnd=UTF-8 | ||
encoding/readme.md=UTF-8 |
5 changes: 0 additions & 5 deletions
5
...penems.backend.metadata.file/test/io/openems/backend/metadata/file/provider/FileTest.java
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
io.openems.common/resources/templates/controller/$testSrcDir$/$basePackageDir$/MyConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package $basePackageName$; | ||
|
||
import io.openems.edge.common.test.AbstractComponentConfig; | ||
|
||
@SuppressWarnings("all") | ||
public class MyConfig extends AbstractComponentConfig implements Config { | ||
|
||
protected static class Builder { | ||
private String id; | ||
// private String setting0; | ||
|
||
private Builder() { | ||
} | ||
|
||
public Builder setId(String id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
// public Builder setSetting0(String setting0) { | ||
// this.setting0 = setting0; | ||
// return this; | ||
// } | ||
|
||
public MyConfig build() { | ||
return new MyConfig(this); | ||
} | ||
} | ||
|
||
/** | ||
* Create a Config builder. | ||
* | ||
* @return a {@link Builder} | ||
*/ | ||
public static Builder create() { | ||
return new Builder(); | ||
} | ||
|
||
private final Builder builder; | ||
|
||
private MyConfig(Builder builder) { | ||
super(Config.class, builder.id); | ||
this.builder = builder; | ||
} | ||
|
||
// @Override | ||
// public String setting0() { | ||
// return this.builder.setting0; | ||
// } | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...common/resources/templates/controller/$testSrcDir$/$basePackageDir$/MyControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package $basePackageName$; | ||
|
||
import org.junit.Test; | ||
|
||
import io.openems.edge.common.test.AbstractComponentTest.TestCase; | ||
import io.openems.edge.controller.test.ControllerTest; | ||
|
||
public class MyControllerTest { | ||
|
||
private static final String CTRL_ID = "ctrl0"; | ||
|
||
@Test | ||
private void test() throws Exception { | ||
new ControllerTest(new MyController()) // | ||
.activate(MyConfig.create() // | ||
.setId(CTRL_ID) // | ||
.build()) | ||
.next(new TestCase()); | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...nems.common/resources/templates/device-modbus/$testSrcDir$/$basePackageDir$/MyConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package $basePackageName$; | ||
|
||
import io.openems.common.utils.ConfigUtils; | ||
import io.openems.edge.batteryinverter.kaco.blueplanetgridsave.MyConfig.Builder; | ||
import io.openems.edge.common.test.AbstractComponentConfig; | ||
|
||
@SuppressWarnings("all") | ||
public class MyConfig extends AbstractComponentConfig implements Config { | ||
|
||
protected static class Builder { | ||
private String id; | ||
private String modbusId = null; | ||
|
||
private Builder() { | ||
} | ||
|
||
public Builder setId(String id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
public Builder setModbusId(String modbusId) { | ||
this.modbusId = modbusId; | ||
return this; | ||
} | ||
|
||
public MyConfig build() { | ||
return new MyConfig(this); | ||
} | ||
} | ||
|
||
/** | ||
* Create a Config builder. | ||
* | ||
* @return a {@link Builder} | ||
*/ | ||
public static Builder create() { | ||
return new Builder(); | ||
} | ||
|
||
private final Builder builder; | ||
|
||
private MyConfig(Builder builder) { | ||
super(Config.class, builder.id); | ||
this.builder = builder; | ||
} | ||
|
||
@Override | ||
public String modbus_id() { | ||
return this.builder.modbusId; | ||
} | ||
|
||
@Override | ||
public String Modbus_target() { | ||
return ConfigUtils.generateReferenceTargetFilter(this.id(), this.modbus_id()); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...n/resources/templates/device-modbus/$testSrcDir$/$basePackageDir$/MyModbusDeviceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package $basePackageName$; | ||
|
||
import org.junit.Test; | ||
|
||
import io.openems.edge.common.test.AbstractComponentTest.TestCase; | ||
import io.openems.common.types.ChannelAddress; | ||
import io.openems.edge.batteryinverter.kaco.blueplanetgridsave.KacoSunSpecModel; | ||
import io.openems.edge.bridge.modbus.test.DummyModbusBridge; | ||
import io.openems.edge.common.test.ComponentTest; | ||
|
||
public class MyModbusDeviceTest { | ||
|
||
private static final String COMPONENT_ID = "component0"; | ||
|
||
private static final String MODBUS_ID = "modbus0"; | ||
|
||
@Test | ||
private void test() throws Exception { | ||
new ComponentTest(new MyModbusDevice()) // | ||
.addReference("setModbus", new DummyModbusBridge(MODBUS_ID)) // | ||
.activate(MyConfig.create() // | ||
.setId(COMPONENT_ID) // | ||
.setModbusId(MODBUS_ID) // | ||
.build()) | ||
.next(new TestCase()); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
io.openems.common/resources/templates/device/$testSrcDir$/$basePackageDir$/MyConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package $basePackageName$; | ||
|
||
import io.openems.edge.common.test.AbstractComponentConfig; | ||
|
||
@SuppressWarnings("all") | ||
public class MyConfig extends AbstractComponentConfig implements Config { | ||
|
||
protected static class Builder { | ||
private String id; | ||
// private String setting0; | ||
|
||
private Builder() { | ||
} | ||
|
||
public Builder setId(String id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
// public Builder setSetting0(String setting0) { | ||
// this.setting0 = setting0; | ||
// return this; | ||
// } | ||
|
||
public MyConfig build() { | ||
return new MyConfig(this); | ||
} | ||
} | ||
|
||
/** | ||
* Create a Config builder. | ||
* | ||
* @return a {@link Builder} | ||
*/ | ||
public static Builder create() { | ||
return new Builder(); | ||
} | ||
|
||
private final Builder builder; | ||
|
||
private MyConfig(Builder builder) { | ||
super(Config.class, builder.id); | ||
this.builder = builder; | ||
} | ||
|
||
// @Override | ||
// public String setting0() { | ||
// return this.builder.setting0; | ||
// } | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
io.openems.common/resources/templates/device/$testSrcDir$/$basePackageDir$/MyDeviceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package $basePackageName$; | ||
|
||
import org.junit.Test; | ||
|
||
import io.openems.edge.common.test.AbstractComponentTest.TestCase; | ||
import io.openems.edge.common.test.ComponentTest; | ||
|
||
public class MyDeviceTest { | ||
|
||
private static final String COMPONENT_ID = "component0"; | ||
|
||
@Test | ||
private void test() throws Exception { | ||
new ComponentTest(new MyDevice()) // | ||
.activate(MyConfig.create() // | ||
.setId(COMPONENT_ID) // | ||
.build()) | ||
.next(new TestCase()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
io.openems.common/src/io/openems/common/utils/ConfigUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.openems.common.utils; | ||
|
||
public class ConfigUtils { | ||
|
||
private ConfigUtils() { | ||
} | ||
|
||
/** | ||
* Generates a target filter for a Declarative Service @Reference member. | ||
* | ||
* <p> | ||
* Usage: | ||
* | ||
* <pre> | ||
* generateReferenceTargetFilter(config.service_pid(), "Controllers", controllersIds); | ||
* </pre> | ||
* | ||
* <p> | ||
* Generates a 'target' filter on the 'Controllers' member so, that the the | ||
* expected service to be injected needs to fulfill: | ||
* <ul> | ||
* <li>the service must be enabled | ||
* <li>the service must not have the same PID as the calling component | ||
* <li>the service "id" must be one of the provided "ids" | ||
* </ul> | ||
* | ||
* @param pid PID of the calling component (use 'config.service_pid()' or | ||
* '(String)prop.get(Constants.SERVICE_PID)'; if null, PID filter is | ||
* not added to the resulting target filter | ||
* @param ids Component IDs to be filtered for; for empty list, no ids are added | ||
* to the target filter | ||
* @return the target filter | ||
*/ | ||
public static String generateReferenceTargetFilter(String pid, String... ids) { | ||
// target component must be enabled | ||
StringBuilder targetBuilder = new StringBuilder("(&(enabled=true)"); | ||
if (pid != null && !pid.isEmpty()) { | ||
// target component must not be the same as the calling component | ||
targetBuilder.append("(!(service.pid=" + pid + "))"); | ||
} | ||
// add filter for given Component-IDs | ||
if (ids.length > 0) { | ||
targetBuilder.append("(|"); | ||
for (String id : ids) { | ||
targetBuilder.append("(id=" + id + ")"); | ||
} | ||
targetBuilder.append(")"); | ||
} | ||
targetBuilder.append(")"); | ||
return targetBuilder.toString(); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
io.openems.common/test/io/openems/common/utils/ConfigUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.openems.common.utils; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
|
||
public class ConfigUtilsTest { | ||
|
||
private static final String PID = "Abc.Def.12345"; | ||
|
||
private static final String CTRL0_ID = "ctrl0"; | ||
private static final String CTRL1_ID = "ctrl1"; | ||
|
||
@Test | ||
public void testGenerateReferenceTargetFilter() { | ||
assertEquals(// | ||
"(&(enabled=true)(!(service.pid=" + PID + "))(|(id=" + CTRL0_ID + ")))", // | ||
ConfigUtils.generateReferenceTargetFilter(PID, CTRL0_ID)); | ||
|
||
assertEquals(// | ||
"(&(enabled=true)(!(service.pid=" + PID + "))(|(id=" + CTRL0_ID + ")(id=" + CTRL1_ID + ")))", // | ||
ConfigUtils.generateReferenceTargetFilter(PID, CTRL0_ID, CTRL1_ID)); | ||
|
||
assertEquals(// | ||
"(&(enabled=true))", // | ||
ConfigUtils.generateReferenceTargetFilter(null)); | ||
|
||
assertEquals(// | ||
"(&(enabled=true)(!(service.pid=" + PID + ")))", // | ||
ConfigUtils.generateReferenceTargetFilter(PID)); | ||
|
||
assertEquals(// | ||
"(&(enabled=true)(|(id=" + CTRL0_ID + ")))", // | ||
ConfigUtils.generateReferenceTargetFilter(null, CTRL0_ID)); | ||
} | ||
|
||
} |
Oops, something went wrong.