Skip to content

Commit

Permalink
java: fix after keyname overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
kodebach committed Oct 2, 2020
1 parent 33c2c53 commit 1bf60ee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.libelektra.exception.model;

import java.util.Arrays;
import org.libelektra.Key;

public class WarningEntry
Expand All @@ -15,11 +16,14 @@ public class WarningEntry
/**
* Extracts warning information from the errorKey
* @param key the errorkey containing the warnings/* metakeys
* @param current The current entry you want to parse, e.g., (key, 0) will search for entries with "warnings/#00"
* @param current The current entry you want to parse, e.g., (key, 0) will search for entries with "warnings/#0"
*/
public WarningEntry (Key key, int current)
{
final String warningKeyName = String.format ("warnings/#%02d", current);
final String warningIndex = Integer.toString (current);
char[] underscores = new char[warningIndex.length () - 1];
Arrays.fill (underscores, '_');
final String warningKeyName = "warnings/#" + new String (underscores) + warningIndex;
warningNumber = key.getMeta (warningKeyName + "/number").getString ();
reason = key.getMeta (warningKeyName + "/reason").getString ();
module = key.getMeta (warningKeyName + "/module").getString ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class KeyTest
{

static final String KEY_1_NAME = "/key_test/1/key_name";
static final String KEY_1_NAME_PART_1 = "";
static final String KEY_1_NAME_PART_1 = "\u0001";
static final String KEY_1_NAME_PART_2 = "key_test";
static final String KEY_1_NAME_PART_3 = "1";
static final String KEY_1_NAME_PART_4 = "key_name";
Expand All @@ -22,7 +22,7 @@ public class KeyTest
static final String KEY_1_META_2_VALUE = "meta_2_value";

static final String KEY_2_NAME = "/key_test/2/key_name";
static final String KEY_2_NAME_PART_1 = "";
static final String KEY_2_NAME_PART_1 = "\u0001";
static final String KEY_2_NAME_PART_2 = "key_test";
static final String KEY_2_NAME_PART_3 = "2";
static final String KEY_2_NAME_PART_4 = "key_name";
Expand Down Expand Up @@ -195,10 +195,10 @@ public class KeyTest

// check meta
final Key meta_1 = key.currentMeta ();
assertEquals (KEY_1_META_1_NAME, meta_1.getName ());
assertEquals ("meta:" + KEY_1_META_1_NAME, meta_1.getName ());
assertEquals (KEY_1_META_1_VALUE, meta_1.getString ());
final Key meta_2 = key.nextMeta ();
assertEquals (KEY_1_META_2_NAME, meta_2.getName ());
assertEquals ("meta:" + KEY_1_META_2_NAME, meta_2.getName ());
assertEquals (KEY_1_META_2_VALUE, meta_2.getString ());

// setup another key
Expand All @@ -208,10 +208,10 @@ public class KeyTest

// check meta for second key
final Key meta_1_2 = key2.currentMeta ();
assertEquals (KEY_1_META_1_NAME, meta_1_2.getName ());
assertEquals ("meta:" + KEY_1_META_1_NAME, meta_1_2.getName ());
assertEquals (KEY_1_META_1_VALUE, meta_1_2.getString ());
final Key meta_2_2 = key2.nextMeta ();
assertEquals (KEY_1_META_2_NAME, meta_2_2.getName ());
assertEquals ("meta:" + KEY_1_META_2_NAME, meta_2_2.getName ());
assertEquals (KEY_1_META_2_VALUE, meta_2_2.getString ());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ public class WarningEntryTest
String module = "kdb";
String reason = "This is a testerror";

final String warningKeyName = String.format ("warnings/#00", 0);
final String warningKeyName = String.format ("warnings/#0", 0);
Key warningKey = Key.create ("user:/temporary/errorkey");
warningKey.setMeta ("warnings/#00/number", errorNumber);
warningKey.setMeta ("warnings/#00/configfile", configFile);
warningKey.setMeta ("warnings/#00/mountpoint", mountpoint);
warningKey.setMeta ("warnings/#00/file", file);
warningKey.setMeta ("warnings/#00/line", line);
warningKey.setMeta ("warnings/#00/module", module);
warningKey.setMeta ("warnings/#00/reason", reason);
warningKey.setMeta ("warnings/#0/number", errorNumber);
warningKey.setMeta ("warnings/#0/configfile", configFile);
warningKey.setMeta ("warnings/#0/mountpoint", mountpoint);
warningKey.setMeta ("warnings/#0/file", file);
warningKey.setMeta ("warnings/#0/line", line);
warningKey.setMeta ("warnings/#0/module", module);
warningKey.setMeta ("warnings/#0/reason", reason);

WarningEntry warningEntry = new WarningEntry (warningKey, 0);

Expand Down

0 comments on commit 1bf60ee

Please sign in to comment.