Skip to content

Commit 25a8b6c

Browse files
changing the tracks settings view to only check settings when clicking the checkSettings button.
You can now save invalid settings. readding tests that apparently were deleted earlier git-svn-id: http://android-shuffle.googlecode.com/svn/trunk@214 c433d9f2-e643-0410-a449-b9b772e888ec
1 parent 236e509 commit 25a8b6c

File tree

8 files changed

+317
-54
lines changed

8 files changed

+317
-54
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package org.dodgybits.android.shuffle.test;
2+
3+
import java.io.StringReader;
4+
5+
import org.dodgybits.shuffle.android.core.model.Context;
6+
import org.dodgybits.shuffle.android.core.model.Id;
7+
import org.dodgybits.shuffle.android.synchronisation.tracks.parsing.ContextParser;
8+
import org.xmlpull.v1.XmlPullParser;
9+
import org.xmlpull.v1.XmlPullParserException;
10+
11+
import android.util.Xml;
12+
13+
import junit.framework.Assert;
14+
import junit.framework.TestCase;
15+
16+
public class ContextParserTests extends TestCase {
17+
18+
public ContextParser CreateSUT() {
19+
return new ContextParser(null);
20+
}
21+
public void testContextParserBasicParsingTest() {
22+
XmlPullParser xmlParser = Xml.newPullParser();
23+
24+
try {
25+
xmlParser.setInput(new StringReader("<context>"+
26+
"<created-at type=\"datetime\">2010-01-09T21:20:39+01:00</created-at>"+
27+
"<hide type=\"boolean\">false</hide>"+
28+
"<id type=\"integer\">3710</id>"+
29+
"<name>Online</name>"+
30+
"<position type=\"integer\">1</position>"+
31+
"<updated-at type=\"datetime\">2010-02-03T10:37:19+01:00</updated-at>"+
32+
"</context>"));
33+
} catch (XmlPullParserException e) {
34+
// TODO Auto-generated catch block
35+
e.printStackTrace();
36+
}
37+
ContextParser parser = CreateSUT();
38+
Context context = parser.parseSingle(xmlParser).getResult();
39+
Assert.assertEquals("Online", context.getName());
40+
Assert.assertEquals(Id.create(3710), context.getTracksId());
41+
Assert.assertEquals(1265189839000l, context.getModifiedDate());
42+
43+
44+
}
45+
46+
public void testContextParserReturnsNullOnFailedParsing() {
47+
XmlPullParser xmlParser = Xml.newPullParser();
48+
49+
try {
50+
xmlParser.setInput(new StringReader("<context>"+
51+
"<created-at type=\"datetime\">2010-01-09T21:20:39+01:00</created-at>"+
52+
"<hide type=\"boolean\">false</hide>"+
53+
"<id type=\"integer\">3710</id>"+
54+
"<name>Online</name>"+
55+
"<position type=\"integer\">1</position>"+
56+
"<updated-at type=\"datetime\">2010-02-03T10:37:19+01:00</updated-at>"+
57+
"</contxt>"));
58+
} catch (XmlPullParserException e) {
59+
// TODO Auto-generated catch block
60+
e.printStackTrace();
61+
}
62+
ContextParser parser = CreateSUT();
63+
Context context = parser.parseSingle(xmlParser).getResult();
64+
Assert.assertEquals(context, null);
65+
66+
67+
}
68+
69+
70+
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package org.dodgybits.android.shuffle.test;
2+
3+
import java.io.StringReader;
4+
5+
6+
import org.dodgybits.shuffle.android.core.model.Id;
7+
import org.dodgybits.shuffle.android.core.model.Project;
8+
import org.dodgybits.shuffle.android.synchronisation.tracks.parsing.IContextLookup;
9+
import org.dodgybits.shuffle.android.synchronisation.tracks.parsing.ProjectParser;
10+
import org.xmlpull.v1.XmlPullParser;
11+
import org.xmlpull.v1.XmlPullParserException;
12+
13+
import android.util.Xml;
14+
import junit.framework.Assert;
15+
import junit.framework.TestCase;
16+
17+
public class ProjectParserTests extends TestCase {
18+
public ProjectParser CreateSUT() {
19+
return new ProjectParser(new IContextLookup() {
20+
21+
@Override
22+
public Id findContextIdByTracksId(Id tracksId) {
23+
// TODO Auto-generated method stub
24+
return Id.create(1234);
25+
}
26+
}, null);
27+
}
28+
public void testProjectParserBasicParsingTest() {
29+
XmlPullParser xmlParser = Xml.newPullParser();
30+
31+
try {
32+
xmlParser.setInput(new StringReader("<project>"+
33+
"<completed-at type=\"datetime\" nil=\"true\"/>"+
34+
"<created-at type=\"datetime\">2010-01-09T21:21:13+01:00</created-at>"+
35+
"<default-context-id type=\"integer\" nil=\"true\"/>"+
36+
"<default-tags nil=\"true\"/>"+
37+
"<description nil=\"true\"/>"+
38+
"<id type=\"integer\">4532</id>"+
39+
"<name>Homework</name>"+
40+
"<position type=\"integer\">1</position>"+
41+
"<state>active</state>"+
42+
"<updated-at type=\"datetime\">2010-02-03T10:37:19+01:00</updated-at>"+
43+
"</project>"));
44+
} catch (XmlPullParserException e) {
45+
// TODO Auto-generated catch block
46+
e.printStackTrace();
47+
}
48+
ProjectParser parser = CreateSUT();
49+
Project project = parser.parseSingle(xmlParser).getResult();
50+
Assert.assertEquals("Homework", project.getName());
51+
Assert.assertEquals(Id.create(4532), project.getTracksId());
52+
Assert.assertEquals(1265189839000l, project.getModifiedDate());
53+
assertEquals(Id.NONE, project.getDefaultContextId());
54+
assertEquals(false, project.isArchived());
55+
56+
57+
}
58+
public void testProjectParserBasicParsingTestWithDefaultContext() {
59+
XmlPullParser xmlParser = Xml.newPullParser();
60+
61+
try {
62+
xmlParser.setInput(new StringReader("<project>"+
63+
"<completed-at type=\"datetime\" nil=\"true\"/>"+
64+
"<created-at type=\"datetime\">2010-01-09T21:21:13+01:00</created-at>"+
65+
"<default-context-id type=\"integer\">2222</default-context-id>"+
66+
"<default-tags nil=\"true\"/>"+
67+
"<description nil=\"true\"/>"+
68+
"<id type=\"integer\">4532</id>"+
69+
"<name>Homework</name>"+
70+
"<position type=\"integer\">1</position>"+
71+
"<state>active</state>"+
72+
"<updated-at type=\"datetime\">2010-02-03T10:37:19+01:00</updated-at>"+
73+
"</project>"));
74+
} catch (XmlPullParserException e) {
75+
// TODO Auto-generated catch block
76+
e.printStackTrace();
77+
}
78+
ProjectParser parser = CreateSUT();
79+
Project project = parser.parseSingle(xmlParser).getResult();
80+
Assert.assertEquals("Homework", project.getName());
81+
Assert.assertEquals(Id.create(4532), project.getTracksId());
82+
Assert.assertEquals(1265189839000l, project.getModifiedDate());
83+
assertEquals(Id.create(1234), project.getDefaultContextId());
84+
assertEquals(false, project.isArchived());
85+
86+
87+
}
88+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package org.dodgybits.android.shuffle.test;
2+
3+
import java.io.StringReader;
4+
5+
import junit.framework.Assert;
6+
import junit.framework.TestCase;
7+
8+
import org.dodgybits.shuffle.android.core.model.Id;
9+
import org.dodgybits.shuffle.android.core.model.Task;
10+
import org.dodgybits.shuffle.android.synchronisation.tracks.parsing.IContextLookup;
11+
import org.dodgybits.shuffle.android.synchronisation.tracks.parsing.IProjectLookup;
12+
import org.dodgybits.shuffle.android.synchronisation.tracks.parsing.TaskParser;
13+
import org.xmlpull.v1.XmlPullParser;
14+
import org.xmlpull.v1.XmlPullParserException;
15+
16+
import android.util.Xml;
17+
18+
public class TaskParserTests extends TestCase {
19+
public TaskParser CreateSUT() {
20+
return new TaskParser(new IContextLookup() {
21+
22+
@Override
23+
public Id findContextIdByTracksId(Id tracksId) {
24+
// TODO Auto-generated method stub
25+
return Id.create(1234);
26+
}
27+
}, new IProjectLookup() {
28+
29+
@Override
30+
public Id findProjectIdByTracksId(Id tracksId) {
31+
// TODO Auto-generated method stub
32+
return Id.create(2345);
33+
}
34+
}, null);
35+
}
36+
public void testTaskParserBasicParsingTest() {
37+
XmlPullParser xmlParser = Xml.newPullParser();
38+
39+
try {
40+
xmlParser.setInput(new StringReader("<todo>"+
41+
"<completed-at type=\"datetime\" nil=\"true\"/>"+
42+
"<context-id type=\"integer\">3711</context-id>"+
43+
"<created-at type=\"datetime\">2009-10-26T22:23:42+01:00</created-at>"+
44+
"<description>Läs getting things done igen</description>"+
45+
"<due type=\"datetime\" nil=\"true\"/>"+
46+
"<id type=\"integer\">25076</id>"+
47+
"<ip-address>90.232.35.15</ip-address>"+
48+
"<notes>Primärt kring idéer och projekt</notes>"+
49+
"<project-id type=\"integer\">4558</project-id>"+
50+
"<recurring-todo-id type=\"integer\" nil=\"true\"/>"+
51+
"<show-from type=\"datetime\" nil=\"true\"/>"+
52+
"<state>active</state>"+
53+
"<updated-at type=\"datetime\">2010-02-03T10:37:19+01:00</updated-at>"+
54+
"</todo>"));
55+
} catch (XmlPullParserException e) {
56+
// TODO Auto-generated catch block
57+
e.printStackTrace();
58+
}
59+
TaskParser parser = CreateSUT();
60+
Task task = parser.parseSingle(xmlParser).getResult();
61+
Assert.assertEquals("Läs getting things done igen", task.getDescription());
62+
Assert.assertEquals(Id.create(25076), task.getTracksId());
63+
Assert.assertEquals(1265189839000l, task.getModifiedDate());
64+
assertEquals("Primärt kring idéer och projekt", task.getDetails());
65+
assertEquals("context id was wrong",Id.create(1234), task.getContextId() );
66+
assertEquals("project id was wrong",Id.create(2345), task.getProjectId() );
67+
assertEquals("due date was wrong",0,task.getDueDate());
68+
assertEquals("start date was wrong",0,task.getStartDate());
69+
70+
71+
}
72+
}

client/.classpath

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<classpath>
3-
<classpathentry kind="src" path="src"/>
4-
<classpathentry kind="src" path="gen"/>
5-
<classpathentry combineaccessrules="false" kind="src" path="/Shuffle-DTO"/>
6-
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
7-
<classpathentry kind="lib" path="/Shuffle-DTO/lib/protobuf-java-2.2.0.jar"/>
8-
<classpathentry kind="lib" path="lib/FlurryAgent.jar"/>
9-
<classpathentry kind="lib" path="lib/guice-2.0-no_aop.jar"/>
10-
<classpathentry kind="lib" path="lib/roboguice-1.0.jar" sourcepath="/Users/andy/android/3rd_party_android/roboguice/roboguice/src/main/java"/>
11-
<classpathentry kind="output" path="bin"/>
12-
</classpath>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="gen"/>
5+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
6+
<classpathentry kind="lib" path="lib/FlurryAgent.jar"/>
7+
<classpathentry kind="lib" path="lib/guice-2.0-no_aop.jar"/>
8+
<classpathentry kind="lib" path="lib/roboguice-1.0.jar" sourcepath="/Users/andy/android/3rd_party_android/roboguice/roboguice/src/main/java"/>
9+
<classpathentry kind="lib" path="/dto/lib/protobuf-java-2.2.0.jar"/>
10+
<classpathentry combineaccessrules="false" kind="src" path="/dto"/>
11+
<classpathentry kind="output" path="bin"/>
12+
</classpath>

client/res/layout/synchronize_settings.xml

+7-2
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,20 @@
7676
<EditText android:id="@+id/pass" android:layout_width="fill_parent"
7777
android:layout_height="wrap_content"
7878
android:layout_alignParentLeft="true"
79-
8079
android:hint="@string/tracks_pass"
8180
android:singleLine="true"
8281
android:inputType="textPassword"
8382
android:maxLength="250"
8483
style="@style/text_editable"
8584
>
8685
</EditText>
87-
86+
87+
<Button android:id="@+id/checkSettings" android:layout_width="fill_parent"
88+
android:text="@string/tracks_check_settings"
89+
android:layout_height="wrap_content"
90+
android:hint="@string/tracks_check_settings"
91+
/>
92+
8893
<TextView android:id="@+id/pass_label"
8994
android:layout_width="fill_parent"
9095
android:layout_height="wrap_content"

client/res/values/strings.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ allow that, you can turn it off under Settings.</string>
278278
<string name="doneWithProjects">Done with Projects</string>
279279
<string name="tracks_failed_to_check_url">Could not load contexts using these settings, something is wrong with them</string>
280280
<string name="tracks_background_sync">Background synchronization interval</string>
281-
<string name="sync_interval_none">Never</string>
281+
<string name="tracks_check_settings">Check settings</string><string name="tracks_settings_valid">Settings are valid</string><string name="sync_interval_none">Never</string>
282282
<string name="sync_interval_30min">30 minutes</string>
283283
<string name="sync_interval_1h">1 hour</string>
284284
<string name="sync_interval_2h">2 hours</string>
@@ -434,4 +434,6 @@ For feedback or bug reports, please check http://code.google.com/p/android-shuff
434434
<item quantity="other"><xliff:g id="count">%d</xliff:g> days</item>
435435
</plurals>
436436

437+
438+
437439
</resources>

0 commit comments

Comments
 (0)